|
template<typename Elem , typename Traits > |
std::basic_ostream< Elem,
Traits > & | operator<< (std::basic_ostream< Elem, Traits > &out, const uintx &n) |
|
template<typename Elem , typename Traits > |
std::basic_istream< Elem,
Traits > & | operator>> (std::basic_istream< Elem, Traits > &in, uintx &n) |
|
template<typename T , size_t N, typename U , typename V > |
T | uintx_cast (const uintx< N, U, V > &obj) |
| Casts a uintx to another type. More...
|
|
template<size_t Bits = static_cast<size_t>(-1), typename Digit = unsigned int, typename Digits = unsigned long long>
struct gears::math::uintx< Bits, Digit, Digits >
Multi-precision unsigned integer. Basic usage does not need to modify the Digit or Digits template parameters, those are there for memory optimisations on rare cases when necessary. Both types should be unsigned if provided.
This multi-precision integer overloads all mathematical operators except the bitwise operators. The streaming operators operator<<
and operator>>
are provided as well. In order to disable the streaming operators, define GEARS_NO_IOSTREAM
before including the file.
All operations do a "bit-check" after their operations to see if the result fits in the bits provided. The "bit-check" in reality just truncates the result to however many digits can fit under Bits / (sizeof(Digit) * 8)
. It is unclear if this behaviour should change at the moment although it might in the future. A Bits parameter of -1
will avoid the "bit-check".
There are two user-defined literals provided under gears::math::literals
help with the construction of a uintx<>
. An example is provided below.
using namespace gears::math::literals;
auto one = 1902748734897198347123_x;
auto two = "89374128732819928123"_x;
- Template Parameters
-
Bits | Bits of precision needed. Defaults to -1 for "infinite" precision. |
Digit | Underlying type to store its bit properties. |
Digits | Underlying type to store its numeric properties. |
Definition at line 136 of file uintx.hpp.
template<size_t Bits = static_cast<size_t>(-1), typename Digit = unsigned int, typename Digits = unsigned long long>
template<typename Integer , gears::meta::EnableIf< std::is_integral< Integer >> = gears::meta::_>
Constructs uintx from an integer type. uintx is then set to the value provided. No bit-checking is done in this constructor. If the value is negative, then it is made positive before hand.
- Parameters
-
value | Value to set uintx to. |
Definition at line 304 of file uintx.hpp.
template<size_t Bits = static_cast<size_t>(-1), typename Digit = unsigned int, typename Digits = unsigned long long>
template<typename T , size_t N, typename U , typename V >
T uintx_cast |
( |
const uintx< N, U, V > & |
obj | ) |
|
|
friend |
Casts a uintx to another type. This type can be an integer type or a string type. To cast to a string, uintx_cast<std::string>
must be used. If the underlying value of uintx
does not fit in the type casted, then the behaviour is undefined.
- Parameters
-
- Template Parameters
-
- Returns
- Casted value.
Definition at line 641 of file uintx.hpp.