HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Data Fields | Static Public Attributes | Friends
v1::bigint< DigitType, NumDigits, IsSigned > Struct Template Reference

#include <hikogui/numeric/bigint.hpp>

Public Types

using digit_type = DigitType
 
using signed_digit_type = std::make_signed_t<digit_type>
 

Public Member Functions

constexpr bigint () noexcept
 Construct and clear an bigint.
 
constexpr bigint (bigint const &) noexcept=default
 
constexpr bigintoperator= (bigint const &) noexcept=default
 
constexpr bigint (bigint &&) noexcept=default
 
constexpr bigintoperator= (bigint &&) noexcept=default
 
template<std::size_t N, bool S>
requires (N < num_digits)
constexpr bigint (bigint< digit_type, N, S > const &rhs) noexcept
 Construct from a small bigint.
 
template<std::size_t N, bool S>
requires (N < num_digits)
constexpr bigintoperator= (bigint< digit_type, N, S > const &rhs) noexcept
 Assign from a small bigint.
 
constexpr bigint (std::integral auto value) noexcept
 
constexpr bigintoperator= (std::integral auto value) noexcept
 
constexpr bigint (std::string_view str, int base=10)
 
constexpr operator unsigned long long () const noexcept
 
constexpr operator signed long long () const noexcept
 
constexpr operator unsigned long () const noexcept
 
constexpr operator signed long () const noexcept
 
constexpr operator unsigned int () const noexcept
 
constexpr operator signed int () const noexcept
 
constexpr operator unsigned short () const noexcept
 
constexpr operator signed short () const noexcept
 
constexpr operator unsigned char () const noexcept
 
constexpr operator signed char () const noexcept
 
constexpr operator bool () const noexcept
 
constexpr bool is_negative () const noexcept
 
template<std::size_t N, bool S>
constexpr operator bigint< digit_type, N, S > () const noexcept
 
std::string string () const noexcept
 
std::string uuid_string () const noexcept
 
constexpr bigint operator- () const noexcept
 
constexpr bigintoperator<<= (std::size_t rhs) noexcept
 
constexpr bigintoperator>>= (std::size_t rhs) noexcept
 
constexpr bigintoperator*= (bigint const &rhs) noexcept
 
constexpr bigintoperator+= (bigint const &rhs) noexcept
 
constexpr bigintoperator-= (bigint const &rhs) noexcept
 
constexpr bigintoperator&= (bigint const &rhs) noexcept
 
constexpr bigintoperator|= (bigint const &rhs) noexcept
 
constexpr bigintoperator^= (bigint const &rhs) noexcept
 

Static Public Member Functions

static bigint from_big_endian (uint8_t const *data) noexcept
 
static bigint from_little_endian (uint8_t const *data) noexcept
 
static bigint from_big_endian (void const *data) noexcept
 
static bigint from_little_endian (void const *data) noexcept
 

Data Fields

digit_type digits [num_digits]
 Digits, in little endian order.
 

Static Public Attributes

static constexpr auto num_digits = NumDigits
 
static constexpr auto is_signed = IsSigned
 
static constexpr auto bits_per_digit = sizeof(digit_type) * CHAR_BIT
 
static constexpr digit_type zero_digit = 0
 
static constexpr digit_type min1_digit = static_cast<digit_type>(signed_digit_type{-1})
 

Friends

constexpr friend bigint crc (bigint const &lhs, bigint const &rhs) noexcept
 Calculate the remainder of a CRC check.
 
constexpr friend bigint reciprocal (bigint const &rhs)
 Calculate the reciprocal at a certain precision.
 
constexpr friend bool operator== (bigint const &lhs, bigint const &rhs) noexcept
 
constexpr friend std::strong_ordering operator<=> (bigint const &lhs, bigint const &rhs) noexcept
 
constexpr friend bigint operator<< (bigint const &lhs, std::size_t rhs) noexcept
 
constexpr friend bigint operator>> (bigint const &lhs, std::size_t rhs) noexcept
 
constexpr friend bigint operator* (bigint const &lhs, bigint const &rhs) noexcept
 
constexpr friend bigint operator+ (bigint const &lhs, bigint const &rhs) noexcept
 
constexpr friend bigint operator- (bigint const &lhs, bigint const &rhs) noexcept
 
constexpr friend bigint operator~ (bigint const &rhs) noexcept
 
constexpr friend bigint operator| (bigint const &lhs, bigint const &rhs) noexcept
 
constexpr friend bigint operator& (bigint const &lhs, bigint const &rhs) noexcept
 
constexpr friend bigint operator^ (bigint const &lhs, bigint const &rhs) noexcept
 
constexpr friend std::pair< bigint, bigintdiv (bigint const &lhs, bigint const &rhs) noexcept
 
constexpr friend std::pair< bigint, bigintdiv (bigint const &lhs, bigint const &rhs, bigint< digit_type, 2 *num_digits, is_signed > const &rhs_reciprocal) noexcept
 
constexpr friend bigint operator/ (bigint const &lhs, bigint const &rhs) noexcept
 
constexpr friend bigint operator% (bigint const &lhs, bigint const &rhs) noexcept
 
std::ostreamoperator<< (std::ostream &lhs, bigint const &rhs)
 

Detailed Description

template<std::unsigned_integral DigitType, std::size_t NumDigits, bool IsSigned>
struct v1::bigint< DigitType, NumDigits, IsSigned >

High performance big integer implementation.

The bigint is a fixed width integer which will allow the compiler to make aggressive optimizations, unrolling most loops and easy inlining.

Constructor & Destructor Documentation

◆ bigint() [1/2]

template<std::unsigned_integral DigitType, std::size_t NumDigits, bool IsSigned>
constexpr v1::bigint< DigitType, NumDigits, IsSigned >::bigint ( )
inlineconstexprnoexcept

Construct and clear an bigint.

◆ bigint() [2/2]

template<std::unsigned_integral DigitType, std::size_t NumDigits, bool IsSigned>
template<std::size_t N, bool S>
requires (N < num_digits)
constexpr v1::bigint< DigitType, NumDigits, IsSigned >::bigint ( bigint< digit_type, N, S > const & rhs)
inlineconstexprnoexcept

Construct from a small bigint.

Member Function Documentation

◆ operator=()

template<std::unsigned_integral DigitType, std::size_t NumDigits, bool IsSigned>
template<std::size_t N, bool S>
requires (N < num_digits)
constexpr bigint & v1::bigint< DigitType, NumDigits, IsSigned >::operator= ( bigint< digit_type, N, S > const & rhs)
inlineconstexprnoexcept

Assign from a small bigint.

Friends And Related Symbol Documentation

◆ crc

template<std::unsigned_integral DigitType, std::size_t NumDigits, bool IsSigned>
constexpr friend bigint crc ( bigint< DigitType, NumDigits, IsSigned > const & lhs,
bigint< DigitType, NumDigits, IsSigned > const & rhs )
friend

Calculate the remainder of a CRC check.

Parameters
lhsThe number to check.
rhsPolynomial.
Returns
the remainder.

◆ reciprocal

template<std::unsigned_integral DigitType, std::size_t NumDigits, bool IsSigned>
constexpr friend bigint reciprocal ( bigint< DigitType, NumDigits, IsSigned > const & rhs)
friend

Calculate the reciprocal at a certain precision.

N should be two times the size of the eventual numerator.

Parameters
rhsThe divider of 1.
Returns
(1 << (K*sizeof(T)*8)) / rhs

Field Documentation

◆ digits

template<std::unsigned_integral DigitType, std::size_t NumDigits, bool IsSigned>
digit_type v1::bigint< DigitType, NumDigits, IsSigned >::digits[num_digits]

Digits, in little endian order.


The documentation for this struct was generated from the following file: