![]() |
Pangolin
Header-only C++20 plane computational geometry library
|
Arbitrary precision signed integer. More...
#include <bigint.hpp>
Public Member Functions | |
| BigInt ()=default | |
| Default constructor (zero). | |
| BigInt (pgl::detail::extended_integral auto value) | |
| Construct from any integer (including pgl::int128). | |
| template<std::floating_point Float> | |
| BigInt (Float value) | |
| Construct from floating point, truncating toward zero. | |
| bool | isZero () const |
| Whether the value is zero. | |
| bool | isOne () const |
| Whether the value is one. | |
| bool | isNegative () const |
| Whether the value is strictly negative. | |
| bool | fitsInt128 () const |
| Whether the magnitude fits in a single pgl::int128. | |
| bool | fitsInt64 () const |
| Whether the magnitude fits in 63 bits (i.e. in an int64_t). | |
| bool | fitsLimbs (std::size_t limbs) const |
Whether the magnitude occupies at most limbs heap limbs. | |
| int | sign () const |
| Sign of the value: -1, 0, or 1. | |
| BigInt | abs () const |
| Absolute value. | |
| operator pgl::int128 () const | |
| Convert to pgl::int128 (low bits, with sign, when it overflows). | |
| template<std::signed_integral T> | |
| operator T () const | |
| Convert to any narrower signed integer (low bits, with sign). | |
| operator bool () const | |
| operator long double () const | |
| Convert to floating point. | |
| operator double () const | |
| operator float () const | |
| BigInt | operator- () const |
| BigInt | operator+ () const |
| BigInt & | operator+= (const BigInt &o) |
| BigInt & | operator-= (const BigInt &o) |
| BigInt & | operator*= (const BigInt &o) |
| BigInt & | operator/= (const BigInt &o) |
| BigInt & | operator%= (const BigInt &o) |
| BigInt & | operator++ () |
| BigInt | operator++ (int) |
| BigInt & | operator-- () |
| BigInt | operator-- (int) |
| std::strong_ordering | operator<=> (const BigInt &o) const |
| bool | operator== (const BigInt &o) const |
| template<std::floating_point Float> | |
| bool | operator== (Float f) const |
Equality with a floating-point value (true only when f is a whole number equal to this integer). | |
| template<std::floating_point Float> | |
| std::partial_ordering | operator<=> (Float f) const |
| Ordering against a floating-point value (partial: NaN is unordered). | |
Static Public Member Functions | |
| static BigInt | subGeneral (const BigInt &a, const BigInt &b) |
| Cold out-of-line subtraction fallback (a magnitude spilled to limbs). | |
| static BigInt | mulGeneral (const BigInt &a, const BigInt &b, bool neg) |
| Cold out-of-line schoolbook multiplication (a magnitude exceeds int128). | |
Friends | |
| BigInt | operator+ (const BigInt &a, const BigInt &b) |
| BigInt | operator- (const BigInt &a, const BigInt &b) |
| BigInt | operator* (const BigInt &a, const BigInt &b) |
| BigInt | operator/ (const BigInt &a, const BigInt &b) |
| BigInt | operator% (const BigInt &a, const BigInt &b) |
| std::ostream & | operator<< (std::ostream &os, const BigInt &b) |
| std::istream & | operator>> (std::istream &is, BigInt &b) |
Arbitrary precision signed integer.
The value is stored in sign-magnitude form:
|
default |
Default constructor (zero).
|
inline |
Construct from any integer (including pgl::int128).
|
inlineexplicit |
Construct from floating point, truncating toward zero.
The fractional part is discarded (round toward zero); the integer part is kept exactly no matter how large the exponent is, so e.g. 2.0**200 is represented bit-for-bit rather than rounded to a double. The value must be finite. Marked explicit so a stray double never slips into BigInt arithmetic or comparisons implicitly.
|
inline |
Absolute value.
|
inline |
Whether the magnitude fits in a single pgl::int128.
|
inline |
Whether the magnitude fits in 63 bits (i.e. in an int64_t).
Used by Rational to decide when deferred reduction has become urgent: reducing operands while they still fit here keeps the impending multiply or cross-addition within the inline int128 store, off the heap limb path.
|
inline |
Whether the magnitude occupies at most limbs heap limbs.
A value in the inline int128 store occupies none, so fitsLimbs(0) is fitsInt128. Used by Rational to bound how large a deferred fraction may grow before reduction is worth its gcd.
|
inline |
Whether the value is strictly negative.
|
inline |
|
inline |
Whether the value is zero.
Cold out-of-line schoolbook multiplication (a magnitude exceeds int128).
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
Convert to floating point.
|
inlineexplicit |
Convert to pgl::int128 (low bits, with sign, when it overflows).
|
inlineexplicit |
Convert to any narrower signed integer (low bits, with sign).
Written over the concept rather than as one overload per fixed-width alias for the reason pgl::detail::_promote is: int, long and long long are three distinct types, and which two of them the aliases name changes with the data model, so naming aliases leaves the third without a conversion on every platform. That gap is only reachable from a coordinate type that promotes this far, which is how it stayed hidden.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Ordering against a floating-point value (partial: NaN is unordered).
|
inline |
|
inline |
Equality with a floating-point value (true only when f is a whole number equal to this integer).
|
inline |
Sign of the value: -1, 0, or 1.
Cold out-of-line subtraction fallback (a magnitude spilled to limbs).
|
friend |
|
friend |