FWNBI — fixed-width N-bit integers

Implements class template for arbitrary width integers and additional functions for them.

Features of library API:

namespace fwnbi
basic_integer class, with semantic like a fixed width integer
class template
digit collection of types 8, 16, 32 and 64 bit width
namespace
literals collection of numeric literal operators with 128, 256, 512 and 1024 bit width and with both sign
namespace
Functions additional operations with integers
Extension of std integration integers to namespace std

Usage example:

#include "fwnbi.hpp"
#include <iostream>

using namespace fwnbi::literals;

fwnbi::uint256_t factorial(int x) {
    if (x < 0 || x > 57)
        return fwnbi::uint256_t::max();
    fwnbi::uint256_t::digit_type n = x + 1;
    fwnbi::uint256_t out = 1_ull256;
    while (n --> 1) out *= n;
    return out;
}

int main() {
    std::cout << "50! = " << factorial(50) << std::endl;
}

Output:

50! = 30414093201713378043612608166064768844377641568960512000000000000
Go back to GitHub