|
fixed_point128 1.0.1.0
128 bit integer, fixed point and floating point arithmetic for C++20
|
128 bit floating point class. More...
#include <float128.h>
Classes | |
| struct | narrowed |
| A finite value rounded to a narrower binary format, see narrow(). More... | |
Public Member Functions | |
| constexpr | float128 () noexcept |
| Default constructor, creates an instance with a value of zero. | |
| constexpr | float128 (const float128 &rhs) noexcept |
| Copy constructor. | |
| constexpr | float128 (float128 &&rhs) noexcept |
| Move constructor Doesn't modify the right hand side object. Acts like a copy constructor. | |
| constexpr | float128 (uint64_t l, uint64_t h) noexcept |
| Low level constructor. | |
| constexpr | float128 (uint64_t lf, uint64_t hf, uint32_t e, uint32_t s) noexcept |
| Low level constructor. | |
| constexpr | float128 (double x) noexcept |
| Constructor from the double type. | |
| template<typename T> | |
| constexpr | float128 (T x) noexcept |
| Generic constructor for integral and floating-point types. | |
| float128 (const char *x) noexcept | |
| Construct from a string Allows creating very high precision values, approximately 34 decimal digits. Much slower than the other constructors. | |
| float128 (const std::string &x) noexcept | |
| Constructor from std::string. Allows creating very high precision values. Much slower than the other constructors. | |
| constexpr | ~float128 ()=default |
| Destructor. | |
| constexpr float128 & | operator= (const float128 &rhs) noexcept |
| Assignment operator. | |
| constexpr float128 & | operator= (float128 &&rhs) noexcept |
| Move assignment operator. | |
| operator std::string () const noexcept | |
| Converts to a std::string (slow) string holds all meaningful fraction bits. | |
| operator char * () const noexcept | |
| Converts to a C string (slow) string holds all meaningful fraction bits. | |
| void | to_e_format (char *str, int32_t buff_size) const |
| Writes the value in scientific notation into a caller supplied buffer. | |
| constexpr float128 & | operator>>= (int32_t shift) noexcept |
| Shift right this object, dividing it by a power of two. | |
| constexpr float128 & | operator<<= (int32_t shift) noexcept |
| Shift left this object, multiplying it by a power of two. | |
| template<typename T> | |
| constexpr float128 | operator>> (T shift) const noexcept |
| Performs right shift operation. | |
| template<typename T> | |
| constexpr float128 | operator<< (T shift) const noexcept |
| Performs left shift operation. Hinted rather than forced, see operator>> above. | |
| constexpr float128 & | operator+= (const float128 &rhs) noexcept |
| Add a value to this object. | |
| template<typename T> | |
| constexpr float128 & | operator+= (const T &rhs) |
| Add a value to this object. | |
| constexpr float128 & | operator-= (const float128 &rhs) noexcept |
| Subtract a value from this object. | |
| template<typename T> | |
| constexpr float128 & | operator-= (const T &rhs) |
| Subtract a value from this object. | |
| constexpr float128 & | operator*= (const float128 &rhs) noexcept |
| Multiply a value to this object. | |
| constexpr float128 & | square () noexcept |
| Squares this object in place. | |
| template<typename T> | |
| constexpr float128 & | operator*= (const T &rhs) |
| Multiply a value to this object. | |
| float128 & | operator/= (const float128 &rhs) |
| Divide this object by a value. | |
| template<typename T> | |
| float128 & | operator/= (const T &rhs) |
| Divide this object by a value. | |
| constexpr | operator bool () const noexcept |
| Convert to bool. | |
| constexpr bool | operator! () const noexcept |
| Logical not (!). Opposite of operator bool. Uses is_zero() rather than testing the raw words: negative zero has its sign bit set and would otherwise be reported as a non zero value. | |
| constexpr float128 | operator+ () const noexcept |
| Unary +. Returns a copy of the object. | |
| constexpr float128 | operator- () const noexcept |
| Unary -. Returns a copy of the object with sign inverted. | |
| constexpr bool | is_positive () const noexcept |
| Returns true if the value is positive (including zero and NaN) | |
| constexpr bool | is_negative () const noexcept |
| Returns true if the value is negative (including zero and NaN). | |
| constexpr bool | is_zero () const noexcept |
| Returns true if and only if the value is ±0. | |
| constexpr bool | is_finite () const noexcept |
| Returns true if and only if x is zero, subnormal or normal (not infinite or NaN). | |
| constexpr bool | is_subnormal () const noexcept |
| Tests if the value is subnormal: non zero, and below the smallest normal magnitude. | |
| constexpr bool | is_normal () const noexcept |
| Tests if the value is normal (not zero, subnormal, infinite, or NaN) | |
| constexpr bool | is_nan () const |
| Tests if this value is a NaN. | |
| constexpr bool | is_signaling () const |
| Tests if this value is a signaling NaN. | |
| constexpr bool | is_inf () const |
| Tests if this value is an Infinite (negative or positive) | |
| constexpr bool | is_exponent_of_2 () const |
| Tests if the value is an exponent of 2 (fraction part is zero) | |
| constexpr bool | is_special () const |
| return true when the value is either an inf or nan | |
| constexpr bool | is_int () const |
| Returns if the value is an integer (fraction is zero). | |
| constexpr int32_t | get_bit (uint32_t bit) const noexcept |
| get a specific bit within the float128 data | |
| constexpr float128 | get_fraction () const |
| Return the fraction part as a float128. | |
| constexpr uint64_t | get_exponent_bits () const noexcept |
| Reads the biased exponent field out of the high QWORD. | |
| constexpr void | set_exponent_bits (uint64_t e) noexcept |
| Sets the biased exponent field, leaving the fraction and the sign alone. | |
| constexpr uint64_t | get_fraction_bits () const noexcept |
| Reads the upper 48 bits of the fraction out of the high QWORD. | |
| constexpr void | set_fraction_bits (uint64_t f) noexcept |
| Sets the upper 48 bits of the fraction, leaving the exponent and the sign alone. | |
| constexpr void | invert_sign () noexcept |
| Inverts the sign. | |
| constexpr void | set_sign (uint64_t s) noexcept |
| Sets the sign. | |
| constexpr uint32_t | get_sign () const noexcept |
| Gets the sign. | |
| constexpr void | get_bits (uint64_t &l, uint64_t &h) const noexcept |
| Reads the raw binary128 encoding. | |
| constexpr float128_class_t | get_class () const noexcept |
| Classifies the float128 value according to IEEE 754. | |
| constexpr int32_t | get_exponent () const noexcept |
| Returns the exponent of the object - like the base 2 exponent of a floating point A value of 2.1 would return 1, values in the range [0.5,1.0) would return -1. | |
| constexpr void | set_exponent (int32_t e) noexcept |
| Set the exponent. | |
| constexpr void | get_components (uint64_t &l, uint64_t &h, int32_t &e, uint32_t &s) const noexcept |
| break the float into its components. Normalizes subnormal values | |
| constexpr bool | fraction_to_fixed (uint64_t frac[FIXED_WORDS]) const noexcept |
| Expands the fraction part of this value into an exact fixed point number. | |
Conversion to narrower floating point formats | |
IEEE 754-2008 5.4.2 convertFormat: the value is rounded once, in the current direction, to the destination's precision and range - including its subnormal range, which keeps fewer bits than its normal one. A NaN keeps its sign and as much of its payload as fits, and is quieted. | |
| template<int32_t P, int32_t EMIN, int32_t EMAX> | |
| constexpr narrowed | narrow () const noexcept |
| Rounds this finite, non zero value to a narrower binary format. | |
| constexpr uint64_t | nan_payload_top (int32_t shift) const noexcept |
| The top of a NaN's payload, for a narrower format to carry. | |
| constexpr | operator double () const noexcept |
| Operator double. | |
| constexpr | operator float () const noexcept |
| operator float converts to a float | |
Conversion to integers | |
The C++ conversions truncate towards zero, which is IEEE 754-2008's convertToIntegerTowardZero. They used to round to nearest for a magnitude of one or more and truncate below it, which agreed with neither: 0.75 became 0 but 1.75 became 2. A value outside the range of the integer type, or a NaN, is the invalid operation. The result is then defined rather than left undefined as it is for the builtin types: an out of range value saturates at the nearest limit, and a NaN converts to zero. | |
| constexpr uint64_t | truncated_magnitude (bool &overflow) const noexcept |
| The integer part of |x|, truncated towards zero. | |
| template<typename I> | |
| constexpr I | to_integer () const noexcept |
| Converts to an integer type, truncating towards zero. | |
| constexpr | operator uint64_t () const noexcept |
| operator uint64_t converts to a uint64_t, truncating towards zero | |
| constexpr | operator int64_t () const noexcept |
| operator int64_t converts to a int64_t, truncating towards zero | |
| constexpr | operator uint32_t () const noexcept |
| operator uint32_t converts to a uint32_t, truncating towards zero | |
| constexpr | operator int32_t () const noexcept |
| operator int32_t converts to a int32_t, truncating towards zero | |
Static Public Member Functions | |||
| static constexpr uint64_t | fixed_mul_extract (uint64_t frac[FIXED_WORDS], uint64_t mul) noexcept | ||
| Multiplies the fixed point fraction by a small value and returns the part that crossed the binary point. | |||
| static constexpr bool | fixed_is_zero (const uint64_t frac[FIXED_WORDS]) noexcept | ||
| True when every word of the fixed point fraction is zero. | |||
| static constexpr uint64_t | norm_product (uint64_t &l, uint64_t &h, int32_t &e, bool sticky) noexcept | ||
| Normalizes the product of two mantissas to bit 112, handing back the bits it drops. | |||
| static constexpr float128 | nextUp (float128 x) | ||
| Produces the closest value larger than x nextUp(x) is the least floating-point number in the format of x that compares greater than x. If x is the negative number of least magnitude in x’s format, nextUp(x) is −0. nextUp(±0) is the positive number of least magnitude in x’s format. nextUp(+∞) is +∞, and nextUp(−∞) is the finite negative number largest in magnitude. When x is NaN, then the result is according to 6.2. nextUp(x) is quiet except for sNaNs. | |||
| static constexpr float128 | nextDown (float128 x) | ||
| Produces the closest value smaller than x. | |||
| static constexpr float128 | inf () | ||
| Return the infinite constant. | |||
| static constexpr float128 | nan () | ||
| Return the quiet (non-signaling) NaN constant. | |||
| static constexpr float128 | signaling_nan () | ||
| Return a signaling NaN. | |||
| static constexpr float128 | pi () | ||
| Return the value of pi. | |||
| static constexpr float128 | half_pi () | ||
| Return the value of pi / 2. | |||
| static constexpr float128 | quarter_pi () | ||
| Return the value of pi / 4. | |||
| static constexpr float128 | e () | ||
| Return the value of e. | |||
| static constexpr float128 | sqrt_2 () noexcept | ||
| Returns a value of sqrt(2) | |||
| static constexpr float128 | one () noexcept | ||
| Returns a value of 1. | |||
| static constexpr float128 | half () noexcept | ||
| Returns a value of 0.5. | |||
| static constexpr float128 | tenth () noexcept | ||
| Return 0.1 using maximum precision. | |||
| static constexpr float128 | exp10 (int32_t e) noexcept | ||
| Calculates 10^e. | |||
| static constexpr float128 | exp10_double_word (int32_t e) noexcept | ||
| The power of exp10(), for an e whose result is inside the range of the format. | |||
| static float128 | exp10_filtered (int32_t e) noexcept | ||
| exp10_double_word() at run time, raising only the exceptions the result justifies. | |||
| static constexpr bool | is754version1985 (void) | ||
| Returns false; this type does not conform to IEEE 754-1985. | |||
| static constexpr bool | is754version2008 (void) | ||
| Whether the type conforms to IEEE 754-2008 (binary128). | |||
| static constexpr float128 | round_integral (const float128 &x, detail::rounding mode, bool ties_away, bool signal_inexact) noexcept | ||
| Rounds to an integral value (IEEE 754-2008 roundToIntegral, 5.3.1). | |||
| template<typename I> | |||
| static constexpr I | integral_to (const float128 &x) noexcept | ||
| Converts an integral value to an integer type, the way the C rounding functions do. | |||
| static constexpr int32_t | square_compare (uint64_t rl, uint64_t rh, const uint64_t n[4]) noexcept | ||
| Square of a 113 bit significand compared with a 256 bit value. | |||
| static float128 | exp_reduced (const float128 &r) noexcept | ||
| e to the power of a reduced argument, |r| <= ln2/2. | |||
| static float128 | pown_magnitude (const float128 &a, int32_t n) noexcept | ||
| a^n by repeated squaring, for a positive finite a. | |||
| static constexpr bool | log_special (const float128 &x, float128 &result) noexcept | ||
| The arguments every logarithm treats alike (IEEE 754-2008 9.2.1). | |||
| static constexpr float128 | log1p_small_limit () noexcept | ||
| Largest |t| the log1p_small() series is used for. Chosen so twelve terms suffice. | |||
| static float128 | log1p_small (const float128 &t) noexcept | ||
| Natural logarithm of 1+t for |t| <= 2^-4, accurate relative to the result. | |||
| static int64_t | quadrant_of (const float128 &x) noexcept | ||
| Nearest integer to x / (pi/2), the quadrant the argument falls in. | |||
| static int32_t | reduce_large (const float128 &x, float128 &hi, float128 &lo) noexcept | ||
| Reduces an argument of any size: x = n * pi/2 + r, with |r| <= pi/4 (Payne and Hanek). | |||
| static int32_t | reduce_trig (const float128 &x, float128 &hi, float128 &lo) noexcept | ||
| Reduces x to [-pi/4, pi/4], as an unevaluated sum, and returns the quadrant. | |||
| static void | reduce_half_pi (const float128 &x, int64_t n, float128 &hi, float128 &lo) noexcept | ||
| Subtracts n*(pi/2) from x, leaving the residual as an unevaluated sum. | |||
| static constexpr bool | is_odd_int (const float128 &x) noexcept | ||
| True when x is an integer whose last place is one, which is the parity a tie needs. | |||
| static float128 | fmod_magnitude (const float128 &x, const float128 &y, uint64_t "ient, int32_t &half) noexcept | ||
| |x| mod |y|, along with the low bits of the quotient it implies. | |||
| static float128 | lgamma_near_two (const float128 &z) noexcept | ||
| lgamma(2 + z) for |z| <= 1/2, accurate relative to the result. | |||
| static float128 | abs_sin_pi (const float128 &x) noexcept | ||
| |sin(pi * x)| for a finite x that is not an integer, without the error of rounding pi * x. | |||
NaN results | |||
| static constexpr float128 | quiet_nan (const float128 &x) noexcept | ||
| x with its quiet bit set. The payload, and the sign, are kept. | |||
| static constexpr float128 | propagate_nan (const float128 &a, const float128 &b) noexcept | ||
| The result of an operation with a NaN operand (IEEE 754-2008 6.2). | |||
| static constexpr float128 | propagate_nan (const float128 &a, const float128 &b, const float128 &c) noexcept | ||
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |||
| static constexpr float128 | propagate_nan (const float128 &a) noexcept | ||
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |||
| static constexpr float128 | invalid_operation () noexcept | ||
| The result of an invalid operation on non NaN operands, such as inf - inf or 0 / 0. | |||
| static constexpr uint32_t | exact_zero_sign () noexcept | ||
| The sign of an exact zero sum of two operands of opposite sign (IEEE 754-2008 6.3). | |||
Mathematical constants | |||
The binary128 nearest each constant, given as the encoding rather than parsed from a decimal string: the string constructor is accurate to about an ulp, which is one bit too few to define a constant the rest of the library computes from. The set mirrors <numbers>, so a generic function template written against std::numbers has the same names available here. | |||
| static constexpr float128 | two_pi () noexcept | ||
| 2*pi | |||
| static constexpr float128 | inv_pi () noexcept | ||
| 1/pi | |||
| static constexpr float128 | inv_sqrt_pi () noexcept | ||
| 1/sqrt(pi) | |||
| static constexpr float128 | ln2 () noexcept | ||
| Natural logarithm of 2. | |||
| static constexpr float128 | ln10 () noexcept | ||
| Natural logarithm of 10. | |||
| static constexpr float128 | log2_e () noexcept | ||
| Base 2 logarithm of e. | |||
| static constexpr float128 | log10_e () noexcept | ||
| Base 10 logarithm of e. | |||
| static constexpr float128 | log10_2 () noexcept | ||
| Base 10 logarithm of 2. | |||
| static constexpr float128 | sqrt_3 () noexcept | ||
| Square root of 3. | |||
| static constexpr float128 | inv_sqrt_3 () noexcept | ||
| 1/sqrt(3) | |||
| static constexpr float128 | egamma () noexcept | ||
| The Euler-Mascheroni constant. | |||
| static constexpr float128 | phi () noexcept | ||
| The golden ratio. | |||
Unevaluated sums | |||
Calculate the Sine function Ultimately uses sin() with a reduced range of [-pi/4, pi/4]
A value held as a pair of float128 whose sum is the quantity meant, with the second one below the last place of the first. That is 226 bits of significand out of two 113 bit values, which is what the trigonometric argument reduction needs: the residual it produces has to be known to the absolute precision of the result, and near a zero of the sine the result is many orders of magnitude below the argument it came from. | |||
| static void | two_sum (const float128 &a, const float128 &b, float128 &sum, float128 &err) noexcept | ||
| Exact sum of two values, as a rounded sum and the error it made. | |||
| static void | quick_two_sum (const float128 &a, const float128 &b, float128 &sum, float128 &err) noexcept | ||
| Exact sum of two values whose magnitudes are ordered. | |||
Static Public Attributes | |
| static constexpr int32_t | SCALE_LIMIT = 2 * (EXP_BIAS + FRAC_BITS + 1) |
| Largest scaling a shift or ldexp() ever needs: enough to take the largest finite value below half the smallest subnormal, or the smallest subnormal above the largest finite value. Larger counts are clamped to it, which keeps the exponent arithmetic in range. | |
| static constexpr int32_t | LOG2_TERMS = (FRAC_BITS + 1 + 8 + log2_reduction_bits - 1) / log2_reduction_bits |
| Number of Mercator series terms log2() needs. | |
| static constexpr int32_t | FIXED_WORDS = 4 |
| Normalize the fraction so the msb (unity bit) is on bit 112. The fraction value must contain the unity value The exponent component is adjusted based on the bit shift direction required. | |
| static constexpr int32_t | EXP_TERMS = 28 |
| Calculates the exponent of x: e Using the Maclaurin series expansion, the formula is: 1 2 3 x x x exp(x) = 1 + — + — + — + ... 1! 2! 3! | |
| static constexpr int32_t | LOG1P_TERMS = 12 |
| Terms of the log1p_small() series. |s| stays below 2^-4.9, so s^24 is past the last bit. | |
| static constexpr int32_t | COS_TERMS = 16 |
| Terms of the cosine series cos1() runs. Up to pi/4, x^32/32! is below 2^-125. | |
| static constexpr int32_t | STIRLING_TERMS = 16 |
| Terms of the Stirling series lgamma() runs. Sixteen reach 2^-119 for an argument of 32. | |
| static constexpr int32_t | LGAMMA_NEAR_TWO_TERMS = 58 |
| Terms of the series lgamma_near_two() runs. For |z| <= 1/2 the last is below 2^-120 of the sum. | |
| static constexpr int32_t | GAMMA_RECURRENCE_LIMIT = 32 |
| Below this magnitude lgamma() and tgamma() move the argument next to two by the recurrence. | |
Friends | |
| class | fp128_gtest |
| template<typename T> | |
| constexpr float128 | operator+ (float128 lhs, const T &rhs) noexcept |
| Adds 2 values and returns the result. | |
| template<typename T> | |
| constexpr float128 | operator- (float128 lhs, const T &rhs) noexcept |
| subtracts the right hand side operand to this object to and returns the result. | |
| template<typename T> | |
| constexpr float128 | operator* (float128 lhs, const T &rhs) noexcept |
| Multiplies the right hand side operand with this object to and returns the result. | |
| template<typename T> | |
| float128 | operator/ (float128 lhs, const T &rhs) |
| Divides this object by the right hand side operand and returns the result. | |
| template<typename T> requires std::is_arithmetic_v<T> | |
| constexpr float128 | operator+ (const T &lhs, const float128 &rhs) noexcept |
| Adds a scalar and a float128, in that order. | |
| template<typename T> requires std::is_arithmetic_v<T> | |
| constexpr float128 | operator- (const T &lhs, const float128 &rhs) noexcept |
| Subtracts a float128 from a scalar. | |
| template<typename T> requires std::is_arithmetic_v<T> | |
| constexpr float128 | operator* (const T &lhs, const float128 &rhs) noexcept |
| Multiplies a scalar and a float128, in that order. | |
| template<typename T> requires std::is_arithmetic_v<T> | |
| float128 | operator/ (const T &lhs, const float128 &rhs) |
| Divides a scalar by a float128. | |
| template<typename T> requires std::is_arithmetic_v<T> | |
| constexpr float128 | operator<< (const T &lhs, const float128 &rhs) noexcept |
| Shifts a scalar left by a float128 shift count, scaling it by a power of two. | |
| template<typename T> requires std::is_arithmetic_v<T> | |
| constexpr float128 | operator>> (const T &lhs, const float128 &rhs) noexcept |
| Shifts a scalar right by a float128 shift count, scaling it by a power of two. The left operand is widened to float128 first, see operator<< above. | |
| constexpr bool | operator== (const float128 &lhs, const float128 &rhs) noexcept |
| Compare logical/bitwise equal. | |
| template<typename T> requires std::is_arithmetic_v<T> | |
| constexpr bool | operator== (const float128 &lhs, const T &rhs) noexcept |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| template<typename T> requires std::is_arithmetic_v<T> | |
| constexpr bool | operator== (const T &lhs, const float128 &rhs) noexcept |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| constexpr bool | operator!= (const float128 &lhs, const float128 &rhs) noexcept |
| Return true when objects are not equal. Can be used as logical XOR. | |
| template<typename T> requires std::is_arithmetic_v<T> | |
| constexpr bool | operator!= (const float128 &lhs, const T &rhs) noexcept |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| template<typename T> requires std::is_arithmetic_v<T> | |
| constexpr bool | operator!= (const T &lhs, const float128 &rhs) noexcept |
| constexpr bool | operator< (const float128 &lhs, const float128 &rhs) noexcept |
| Return true if this object is small than the other. | |
| template<typename T> | |
| constexpr bool | operator< (const float128 &lhs, const T &rhs) noexcept |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| template<typename T> | |
| constexpr bool | operator< (const T &lhs, const float128 &rhs) noexcept |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| constexpr bool | operator<= (const float128 &lhs, const float128 &rhs) noexcept |
| Return true this object is small or equal than the other. | |
| template<typename T> | |
| constexpr bool | operator<= (const float128 &lhs, const T &rhs) noexcept |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| template<typename T> | |
| constexpr bool | operator<= (const T &lhs, const float128 &rhs) noexcept |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| constexpr bool | operator> (const float128 &lhs, const float128 &rhs) noexcept |
| Return true this object is larger than the other. | |
| template<typename T> | |
| constexpr bool | operator> (const float128 &lhs, const T &rhs) noexcept |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| template<typename T> | |
| constexpr bool | operator> (const T &lhs, const float128 &rhs) noexcept |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| constexpr bool | operator>= (const float128 &lhs, const float128 &rhs) noexcept |
| Return true this object is larger or equal than the other. | |
| template<typename T> | |
| constexpr bool | operator>= (const float128 &lhs, const T &rhs) noexcept |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| template<typename T> | |
| constexpr bool | operator>= (const T &lhs, const float128 &rhs) noexcept |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| constexpr float128 | nan (const float128 &) |
| Return the NaN constant. | |
| constexpr bool | isnan (const float128 &x) |
| Tests if the value is a NaN. | |
| constexpr bool | isinf (const float128 &x) |
| Tests if the value is an Infinite (negative or positive) | |
| constexpr float128 | fabs (const float128 &x) |
| Returns the absolute value of x. | |
| constexpr float128 | floor (const float128 &x) |
| Performs the floor() function, similar to libc's floor(), rounds down towards -infinity. | |
| constexpr float128 | ceil (const float128 &x) |
| Performs the ceil() function, similar to libc's ceil(), rounds up towards infinity. | |
| constexpr float128 | trunc (const float128 &x) |
| Rounds towards zero. | |
| constexpr float128 | round (const float128 &x) |
| Rounds towards the nearest integer. The halfway value (0.5) is rounded away from zero. | |
| constexpr int64_t | llrint (const float128 &x) |
| Rounds x to an integer in the current rounding direction and returns it as int64_t. | |
| constexpr int64_t | llround (const float128 &x) |
| Rounds towards the nearest integer. The halfway value (0.5) is rounded away from zero. | |
| constexpr int32_t | lrint (const float128 &x) |
| Rounds x to an integer in the current rounding direction and returns it as int32_t. | |
| constexpr int32_t | lround (const float128 &x) |
| Rounds towards the nearest integer. The halfway value (0.5) is rounded away from zero. | |
| constexpr int32_t | ilogb (const float128 &x) |
| Retrieves an integer that represents the base-2 exponent of the specified value. | |
| constexpr float128 | copysign (const float128 &x, const float128 &y) |
| returns the value of x with the sign of y. | |
| float128 | fmod (const float128 &x, const float128 &y) |
| Performs the fmod() function, similar to libc's fmod(), returns the remainder of a division x/root. | |
| constexpr float128 | modf (const float128 &x, float128 *iptr) |
| Split into integer and fraction parts. Both results carry the sign of the input variable. | |
| constexpr float128 | fdim (const float128 &x, const float128 &y) |
| Determines the positive difference between the first and second values. | |
| constexpr float128 | fmin (const float128 &x, const float128 &y) |
| Returns the minimum between x and y. | |
| constexpr float128 | fmax (const float128 &x, const float128 &y) |
| Returns the maximum between x and y. | |
| float128 | hypot (const float128 &x, const float128 &y) |
| Calculates the hypotenuse. i.e. sqrt(x^2 + y^2) | |
| constexpr float128 | sqr (float128 x) noexcept |
| Calculates the square of a value. i.e. x^2. | |
| float128 | sqrt (const float128 &x, uint32_t iterations=3) |
| Calculates the square root, correctly rounded. | |
| float128 | cbrt (const float128 x, uint32_t iterations=2) |
| Calculates the cube root. Uses the Halley's method. | |
| float128 | reciprocal (const float128 &x) |
| Calculates the reciprocal of a value, 1 / x, correctly rounded. | |
| void | fact_reciprocal (int x, float128 &res) |
| Factorial reciprocal (inverse). Calculates 1 / x! Maximum supported value of x is 50. | |
| float128 | double_factorial (int x) |
| Returns the double factorial of a number, x!! = x * (x - 2) * (x - 4) * ... | |
| float128 | exp (const float128 &x) |
| Computes e to the power of x. | |
| float128 | exp2 (const float128 &x) |
| Computes 2 to the power of x. | |
| float128 | expm1 (const float128 &x) |
| Calculates the exponent of x and reduces 1 from the result: (e^x) - 1. | |
| float128 | pow (const float128 &x, int32_t y) |
| Computes x to the power of y (IEEE 754-2008 pown) | |
| float128 | pow (const float128 &x, const float128 &y) |
| Computes x to the power of y. | |
| float128 | log (float128 x) |
| Calculates the natural Log (base e) of x: log(x) | |
| float128 | log2 (float128 x) |
| Calculates the Log base 2 of x: y = log2(x) | |
| float128 | log10 (float128 x) |
| Calculates Log base 10 of x: log10(x) | |
| float128 | logb (float128 x) |
| Calculates Log base 2 of x as an integer ignoring the sign of x. Similar to: floor(log2(fabs(x))) | |
| float128 | log1p (float128 x) |
| Calculates the natural Log (base e) of 1 + x: log(1 + x) | |
| float128 | sin1 (float128 x) noexcept |
| Calculate the sine function over a limited range [-0.5pi, 0.5pi] Using the Maclaurin series expansion, the formula is: x^3 x^5 x^7 sin(x) = x - — + — - — + ... 3! 5! 7! | |
| float128 | cos1 (const float128 &x) noexcept |
| Calculate the cosine function over a limited range [-0.5pi, 0.5pi]. | |
| float128 | sin (float128 x) |
| float128 | asin (float128 x) |
| Calculate the inverse sine function. | |
| float128 | cos (float128 x) |
| Calculate the cosine function Ultimately uses sin1() with a reduced range of [-pi/4, pi/4] Sine's Maclaurin series converges faster than Cosine's. | |
| float128 | acos (float128 x) |
| Calculate the inverse cosine function. | |
| float128 | tan (float128 x) |
| Calculate the tangent function tan(x) = sin(x)/cos(x) | |
| float128 | atan (float128 x) |
| Calculate the inverse tangent function. | |
| float128 | atan2 (float128 y, float128 x) |
| Calculate the inverse tangent function of the ratio y / x. | |
| float128 | sinh (const float128 x) |
| Calculate the hyperbolic sine function Use the exponent function which produces more accurate results than the power series. e^x - e^(-x) sinh(x) = ---------— 2. | |
| float128 | asinh (const float128 x) |
| Calculates the inverse hyperbolic sine For positive x: asinh(x) = log(x + sqrt(x^2 + 1)) For negative x, the function returns the result with the sign inverted. | |
| float128 | cosh (const float128 x) |
| Calculate the hyperbolic cosine function over a limited range [-0.5pi, 0.5pi] e^x + e^(-x) cosh(x) = ---------— 2. | |
| float128 | acosh (const float128 x) |
| Calculates the inverse hyperbolic cosine For x >= 1: acosh(x) = log(x + sqrt(x^2 - 1)) For x < 1, the function return zero. | |
| float128 | tanh (const float128 x) |
| Calculates the hyperbolic tangent e^x - e^(-x) tanh(x) = ---------— e^x + e^(-x) | |
| float128 | atanh (const float128 x) |
| Calculates the inverse hyperbolic tangent 1 + x atanh(x) = 0.5 * log( --—) 1 - x. | |
| void | erf_constants (float128 *a, int32_t count) |
| Calculates the Maclaurin series constants for the erf function. The array will hold 1 / (n! * (2n + 1)) | |
| float128 | erf (float128 x) |
| Computes the error function of a value. The erf function return a value in the range -1.0 to 1.0. There's no error return. | |
| float128 | erfc (float128 x) |
| Computes the complementary error function, 1 - erf(x). | |
| constexpr bool | isfinite (const float128 &x) |
| Tests whether x is finite (not infinite and not NaN). | |
| constexpr float128 | fma (float128 x, float128 y, float128 z) |
| Computes (x * y) + z with a single rounding at the end. | |
| constexpr float128 | frexp (float128 x, int *expptr) |
| Gets the mantissa and exponent of a floating-point number. | |
| constexpr float128 | ldexp (float128 x, int exp) |
| Multiplies a floating-point number by an integral power of two. | |
| float128 | nan (const char *payload) |
| A quiet NaN carrying the payload spelled out in the argument. | |
| constexpr float128 | nextafter (const float128 &x, const float128 &y) |
| The representable value next to x in the direction of y. | |
| constexpr float128 | nexttoward (const float128 &x, const float128 &y) |
| The neighbour of x towards y. The same as nextafter: there is no wider type to convert from. | |
| float128 | remainder (const float128 &x, const float128 &y) |
| IEEE 754 remainder: x - n*y with n the quotient rounded to the nearest even integer. | |
| float128 | remquo (const float128 &x, const float128 &y, int *quo) |
| The IEEE remainder together with the low bits of the quotient. | |
| float128 | hypot (const float128 &x, const float128 &y, const float128 &z) |
| Length of the diagonal of a box, computed without an intermediate overflow. | |
| float128 | lgamma (float128 x) |
| Natural logarithm of the absolute value of the gamma function. | |
| float128 | tgamma (float128 x) |
| The gamma function. | |
| constexpr float128 | abs (const float128 &x) |
| Absolute value, the name <cmath> gives the floating point overload alongside fabs. | |
| float128 | operator""_f128 (const char *literal) |
| User-defined literal implementation for constructing float128 from a string. | |
Classification and comparison | |
The <cmath> predicates. They are functions rather than the macros the C header defines, in the same way the standard library's own C++ overloads are, so they take part in overload resolution and can be found by argument dependent lookup. | |
| constexpr bool | signbit (const float128 &x) |
| True when the sign bit is set, including for -0 and for a negative NaN. | |
| constexpr bool | isnormal (const float128 &x) |
| True when x is neither zero, subnormal, infinite nor NaN. | |
| constexpr int | fpclassify (const float128 &x) |
| One of FP_NAN, FP_INFINITE, FP_ZERO, FP_SUBNORMAL or FP_NORMAL. | |
| constexpr bool | isunordered (const float128 &x, const float128 &y) |
| True when either operand is a NaN, so that the two do not compare in any order. | |
| constexpr bool | isgreater (const float128 &x, const float128 &y) |
| x > y, false rather than unordered when either is a NaN. | |
| constexpr bool | isgreaterequal (const float128 &x, const float128 &y) |
| x >= y, false when either is a NaN. | |
| constexpr bool | isless (const float128 &x, const float128 &y) |
| x < y, false when either is a NaN. | |
| constexpr bool | islessequal (const float128 &x, const float128 &y) |
| x <= y, false when either is a NaN. | |
| constexpr bool | islessgreater (const float128 &x, const float128 &y) |
| x < y or x > y, false when either is a NaN. | |
Rounding to the current mode | |
Both round in the current rounding direction, which is to nearest with ties to even unless FP128_IEEE_ENV is defined and fesetround() chose another. They differ in one respect: rint is IEEE 754's roundToIntegralExact and raises the inexact exception when the result differs from its argument, nearbyint never does. round() differs from both: it breaks a tie away from zero whatever the rounding direction. | |
| constexpr float128 | rint (const float128 &x) |
| x rounded to an integral value in the current direction, raising inexact when that changes it. | |
| constexpr float128 | nearbyint (const float128 &x) |
| x rounded to an integral value in the current direction. | |
Exponent manipulation | |
| constexpr float128 | scalbn (const float128 &x, int n) |
| x * 2^n, the same operation ldexp performs. | |
| constexpr float128 | scalbln (const float128 &x, long n) |
| x * 2^n for a long exponent, clamped to what the format can reach. | |
IEEE 754-2008 operations beyond <cmath> | |
Operations clause 5 requires that the C library of the time did not name. They are spelled the way ISO/IEC TS 18661-1, and after it C23, binds them to C. | |
| constexpr bool | totalorder (const float128 &x, const float128 &y) |
| totalOrder(x, y): true when x precedes y, or equals it, in the IEEE 754 total order. | |
| constexpr bool | totalordermag (const float128 &x, const float128 &y) |
| totalOrderMag(x, y): totalorder() of the absolute values. | |
| constexpr float128 | fmaxmag (const float128 &x, const float128 &y) |
| maxNumMag: whichever of x and y has the larger magnitude, or fmax() when they tie. | |
| constexpr float128 | fminmag (const float128 &x, const float128 &y) |
| minNumMag: whichever of x and y has the smaller magnitude, or fmin() when they tie. | |
| constexpr bool | iscanonical (const float128 &x) |
| isCanonical: always true, every binary128 encoding is canonical. | |
| constexpr bool | issignaling (const float128 &x) |
| isSignaling: true for a signaling NaN. | |
| constexpr bool | issubnormal (const float128 &x) |
| isSubnormal: true for a subnormal value, which zero is not. | |
| constexpr bool | iszero (const float128 &x) |
| isZero: true for either zero. | |
| constexpr void | total_order_key (uint64_t &l, uint64_t &h) const noexcept |
| The encoding as a key whose unsigned order is the total order of IEEE 754-2008 5.10. | |
Rounding | |
Every operation whose exact result may not be representable ends in round_pack(), which is the one place a result is rounded. IEEE 754 requires each operation to behave as if it first computed the exact result and then rounded it once, to the destination format, in the current rounding direction - and the destination format includes its subnormal range, where fewer than 113 bits are kept. The operations used to round to 113 bits first and then let set_components() round a second time when the result turned out to be subnormal, which gave the wrong last bit for about one subnormal result in ten. They also decided the direction from a window of three bits, which cannot tell a tie from a value just above one when the bits that settle it lie further down. The shape follows Berkeley SoftFloat's roundPackToF128: the caller hands over a 113 bit significand and a 64 bit word of the bits below it, left aligned, with anything further down jammed into its lowest bit. The top bit of that word is the first bit dropped, and the word being non zero means the result is inexact - which is all any rounding direction needs. | |
| static constexpr uint64_t | MAX_SIG_HIGH = FRAC_UNITY | UPPER_FRAC_MASK |
| The largest finite magnitude's significand, high QWORD, with its leading one at bit 48. | |
| constexpr void | set_components (uint64_t l, uint64_t h, int32_t e, uint32_t s) noexcept |
| Stores a significand and exponent, rounding when the value is subnormal. | |
| static constexpr void | shift_right_jam128_extra (uint64_t &l, uint64_t &h, uint64_t &extra, int32_t dist) noexcept |
| Shifts a significand and its extra word right, keeping a sticky record of what fell off. | |
| static constexpr void | shift_right_jam128 (uint64_t &l, uint64_t &h, int32_t dist) noexcept |
| Shifts a 128 bit value right, jamming any set bit that falls off into the lowest bit. | |
| static constexpr bool | round_increment (detail::rounding mode, uint32_t sign, uint64_t extra) noexcept |
| Whether rounding should add one unit in the last place. | |
| static constexpr float128 | round_pack_edge (uint32_t sign, int32_t exp, uint64_t l, uint64_t h, uint64_t extra, detail::rounding mode) noexcept |
| The slow half of round_pack(): results that overflow or are subnormal. | |
| static constexpr float128 | round_pack (uint32_t sign, int32_t e, uint64_t l, uint64_t h, uint64_t extra) noexcept |
| Rounds an exact result once, in the current rounding direction, and encodes it. | |
| static constexpr float128 | round_pack (uint32_t sign, int32_t e, uint64_t l, uint64_t h, uint64_t extra, detail::rounding mode) noexcept |
| static constexpr float128 | norm_round_pack (uint32_t sign, int32_t e, uint64_t l, uint64_t h, bool sticky) noexcept |
| Normalizes an exact non negative 128 bit significand and rounds it once. | |
| static constexpr float128 | from_fraction128 (uint64_t low, uint64_t high) noexcept |
| Builds a float128 from a 128 bit fraction, a value in [0,1). | |
Wide accumulator | |
A fixed 384 bit unsigned integer, used by fma() to hold the exact sum of a 226 bit product and a 113 bit addend before a single rounding is applied to it. The width is what the two together need in the worst case: whichever of them is larger is placed with its leading bit at the top of the accumulator, which leaves 383-225 = 158 bits below the product and 383-112 = 271 bits below the addend. An operand that does not fit under the other one is more than 158 bits smaller than it, so it cannot influence anything but the sticky bit, and is folded into that instead of being placed. These are implementation details of fma() rather than part of the interface. | |
| static constexpr int32_t | WIDE_WORDS = 6 |
| Words in the accumulator. | |
| static constexpr int32_t | WIDE_BITS = WIDE_WORDS * 64 |
| static constexpr int32_t | WIDE_TOP = WIDE_BITS - 2 |
| Bit the leading one of the larger operand is placed on. | |
| static constexpr void | mul128to256 (uint64_t al, uint64_t ah, uint64_t bl, uint64_t bh, uint64_t res[4]) noexcept |
| Full 256 bit product of two 128 bit values. | |
| static constexpr int32_t | wide_msb (const uint64_t *a, int32_t words) noexcept |
| Index of the highest set bit of a multi word value, or -1 when it is zero. | |
| static constexpr bool | wide_place (uint64_t *acc, const uint64_t *src, int32_t words, int32_t offset) noexcept |
| Writes a value into a zeroed accumulator, shifted to a given bit position. | |
| static constexpr void | wide_add (uint64_t *a, const uint64_t *b) noexcept |
| Adds b into a. The accumulator is wide enough that the sum cannot carry out. | |
| static constexpr void | wide_sub (uint64_t *a, const uint64_t *b) noexcept |
| Subtracts b from a, which must not be smaller. | |
| static constexpr void | wide_dec (uint64_t *a) noexcept |
| Subtracts one from the accumulator, which must not be zero. | |
| static constexpr int32_t | wide_cmp (const uint64_t *a, const uint64_t *b) noexcept |
| Three way comparison of two accumulators. | |
long double | |
What a long double is depends on the platform: a plain double under MSVC, the x87 80 bit extended format on x86 under GCC and Clang, and binary128 itself on AArch64 Linux. The two wider ones are converted through their encoding rather than through double, which would round away the bits they have over it. | |
| constexpr | operator long double () const noexcept |
| operator long double | |
| static constexpr float128 | from_long_double (long double x) noexcept |
| Converts a long double wider than a double, exactly. | |
128 bit floating point class.
This class implements the standard operators a floating point data type.
All of float128's methods are inline for maximum performance.
IEEE 754-2008:
Implementation notes:
Compile time evaluation:
Everything that stays within the 128 bit encoding is constexpr:
Two things make that possible. The bit counting and extended arithmetic intrinsics are not constant expressions, so fp128_shared.h wraps each one in a constexpr function that serves a constant evaluated call from a portable implementation of the same operation. And the fields of the high QWORD are read through the shift and mask accessors rather than the _float128_bits view, because reading the inactive member of a union is not allowed during constant evaluation. A runtime call is unaffected by either.
The rest cannot be constexpr, for one of two reasons:
Definition at line 671 of file float128.h.
|
inlineconstexprnoexcept |
Default constructor, creates an instance with a value of zero.
Definition at line 732 of file float128.h.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Move constructor Doesn't modify the right hand side object. Acts like a copy constructor.
| rhs | Object to copy from |
Definition at line 743 of file float128.h.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Low level constructor.
| lf | Low fraction part (bits 63:0) |
| hf | High fraction part (bits 111:64) |
| e | Exponent |
| s | sign |
Definition at line 757 of file float128.h.
|
inlineconstexprnoexcept |
Constructor from the double type.
| x | Input value |
Definition at line 765 of file float128.h.
|
inlineconstexprnoexcept |
Generic constructor for integral and floating-point types.
Every value of every builtin arithmetic type is representable, so the conversion is exact. float goes through double, which holds it exactly. A long double wider than a double - the x87 extended format, or binary128 itself - is read from its encoding, since a double would round it. Integral types are converted directly. Character pointer types delegate to the const char* constructor.
| T | Source type (must be arithmetic or a character pointer type) |
| x | Input value |
Definition at line 828 of file float128.h.
|
inlinenoexcept |
Construct from a string Allows creating very high precision values, approximately 34 decimal digits. Much slower than the other constructors.
| x | Input string |
Definition at line 884 of file float128.h.
|
inlinenoexcept |
Constructor from std::string. Allows creating very high precision values. Much slower than the other constructors.
| x | Input string |
Definition at line 922 of file float128.h.
|
constexprdefault |
Destructor.
Assignment operator.
| rhs | Object to copy from |
Definition at line 937 of file float128.h.
Move assignment operator.
| rhs | Object to copy from |
Definition at line 948 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
Rounds this finite, non zero value to a narrower binary format.
Overflow produces infinity, or the largest finite value in the two directions that round towards it, and raises the overflow and inexact flags. A result that is tiny after rounding and inexact raises underflow.
| P | Precision of the destination, counting its leading bit whether stored or implicit. At most 64, so the significand fits a single word. |
| EMIN | Exponent of the destination's smallest normal value |
| EMAX | Exponent of its largest finite value |
Definition at line 990 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
The top of a NaN's payload, for a narrower format to carry.
The payload is the fraction below the quiet bit, bits 110:0. A narrower format keeps its top bits, which is where the conversion from that format puts them, so a payload survives the round trip.
| shift | FRAC_BITS - 1 less the payload width of the destination, at least 47 |
Definition at line 1058 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
Operator double.
Correctly rounded in the current direction. Overflow keeps its sign, as does a value too small for the subnormal range, and a NaN keeps its sign and the top 51 bits of its payload.
Definition at line 1070 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
operator float converts to a float
Rounded once, straight to single precision. Going through double, as this used to, rounds twice: 1 + 2^-24 + 2^-82 became 1 + 2^-24 in double, a tie, which then went to 1.0f.
Definition at line 1099 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
The integer part of |x|, truncated towards zero.
| overflow | Set when |x| is 2^64 or more, an infinity included |
Definition at line 1141 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
Converts to an integer type, truncating towards zero.
| I | The integer type |
Definition at line 1162 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
operator uint64_t converts to a uint64_t, truncating towards zero
Definition at line 1198 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
operator int64_t converts to a int64_t, truncating towards zero
Definition at line 1202 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
operator uint32_t converts to a uint32_t, truncating towards zero
Definition at line 1206 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
operator int32_t converts to a int32_t, truncating towards zero
Definition at line 1210 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Converts a long double wider than a double, exactly.
| x | Value to convert |
Definition at line 1244 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
operator long double
The same as the conversion to double where long double is one. Elsewhere correctly rounded to the wider format, or exact where long double is binary128.
Definition at line 1281 of file float128.h.
|
inlinenodiscardnoexcept |
Converts to a std::string (slow) string holds all meaningful fraction bits.
Definition at line 1321 of file float128.h.
|
inlineexplicitnodiscardnoexcept |
Converts to a C string (slow) string holds all meaningful fraction bits.
Definition at line 1326 of file float128.h.
|
inline |
Writes the value in scientific notation into a caller supplied buffer.
Kept for the callers that predate std::format support. Everything it does is also reachable as fp128::to_chars(..., std::chars_format::scientific) or as std::format("{:e}", value), both of which say what they produce more clearly.
| str | Output buffer |
| buff_size | Output buffer size in bytes |
Definition at line 1349 of file float128.h.
|
inlineconstexprnoexcept |
Shift right this object, dividing it by a power of two.
| shift | Bits to shift. Values less than 1 do nothing, high values can cause the value to reach zero. |
Definition at line 1374 of file float128.h.
|
inlineconstexprnoexcept |
Shift left this object, multiplying it by a power of two.
| shift | Bits to shift. Values less than 1 do nothing, high values can cause the value to reach infinity. |
Definition at line 1398 of file float128.h.
|
inlineconstexprnoexcept |
Performs right shift operation.
Hinted rather than forced, unlike the other one line forwarders (see FP128_FORCE_INLINE). What it forwards to is not cheap: operator>>= splits the value into components and reassembles it, which brings the subnormal handling of get_components() and set_components() along with it. Forcing this pair open cost ~9% of the float128 Mandelbrot benchmark, which shifts inside a loop that already inlines an add, a multiply and two squares. Left as a hint, the shift is still inlined wherever the caller has room for it.
| shift | bits to shift |
Definition at line 1429 of file float128.h.
|
inlineconstexprnoexcept |
Performs left shift operation. Hinted rather than forced, see operator>> above.
| shift | bits to shift |
Definition at line 1440 of file float128.h.
Add a value to this object.
| rhs | Right hand side operand |
Definition at line 1451 of file float128.h.
|
inlineconstexpr |
Add a value to this object.
| rhs | Right hand side operand |
Definition at line 1559 of file float128.h.
Subtract a value from this object.
| rhs | Right hand side operand |
Definition at line 1565 of file float128.h.
|
inlineconstexpr |
Subtract a value from this object.
| rhs | Right hand side operand |
Definition at line 1571 of file float128.h.
Multiply a value to this object.
| rhs | Right hand side operand |
Definition at line 1577 of file float128.h.
|
inlineconstexprnoexcept |
Squares this object in place.
Cheaper than operator*=(*this) on several counts:
The result is identical to (*this) * (*this) for every value, specials included.
Definition at line 1684 of file float128.h.
|
inlineconstexpr |
Multiply a value to this object.
| rhs | Right hand side operand |
Definition at line 1749 of file float128.h.
Divide this object by a value.
| rhs | Right hand side operand |
Definition at line 1755 of file float128.h.
|
inline |
Divide this object by a value.
| rhs | Right hand side operand |
Definition at line 1842 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
Convert to bool.
Definition at line 1850 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
Logical not (!). Opposite of operator bool. Uses is_zero() rather than testing the raw words: negative zero has its sign bit set and would otherwise be reported as a non zero value.
Definition at line 1856 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
Unary +. Returns a copy of the object.
Definition at line 1860 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
Unary -. Returns a copy of the object with sign inverted.
Definition at line 1864 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
Returns true if the value is positive (including zero and NaN)
Definition at line 1873 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
Returns true if the value is negative (including zero and NaN).
Definition at line 1878 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
Returns true if and only if the value is ±0.
Definition at line 1883 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
Returns true if and only if x is zero, subnormal or normal (not infinite or NaN).
Definition at line 1888 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
Tests if the value is subnormal: non zero, and below the smallest normal magnitude.
A zero shares the exponent field of the subnormals but is not one of them, as IEEE 754's isSubnormal has it. The arithmetic itself tests the raw field (see get_components()), where treating a zero alike is harmless and saves the test of the fraction.
Definition at line 1898 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
Tests if the value is normal (not zero, subnormal, infinite, or NaN)
Definition at line 1903 of file float128.h.
|
inlinenodiscardconstexpr |
Tests if this value is a NaN.
Definition at line 1908 of file float128.h.
|
inlinenodiscardconstexpr |
Tests if this value is a signaling NaN.
Definition at line 1917 of file float128.h.
|
inlinenodiscardconstexpr |
Tests if this value is an Infinite (negative or positive)
Definition at line 1927 of file float128.h.
|
inlinenodiscardconstexpr |
Tests if the value is an exponent of 2 (fraction part is zero)
Definition at line 1936 of file float128.h.
|
inlinenodiscardconstexpr |
return true when the value is either an inf or nan
Definition at line 1945 of file float128.h.
|
inlinenodiscardconstexpr |
Returns if the value is an integer (fraction is zero).
Definition at line 1954 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
get a specific bit within the float128 data
| bit | bit to get [0,127] |
Definition at line 1975 of file float128.h.
|
inlinenodiscardconstexpr |
Return the fraction part as a float128.
Definition at line 1985 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
Reads the biased exponent field out of the high QWORD.
This accessor and the three below it are the only places that know where the fields sit within the high QWORD, which is the same layout the (l, h, e, s) constructor assembles. They deliberately shift and mask rather than going through the _float128_bits view: that would be a read of the inactive member of a union, which constant evaluation rejects.
Definition at line 2027 of file float128.h.
|
inlineconstexprnoexcept |
Sets the biased exponent field, leaving the fraction and the sign alone.
| e | Biased exponent. Bits above the 15 the field holds are dropped. |
Definition at line 2032 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
Reads the upper 48 bits of the fraction out of the high QWORD.
Definition at line 2037 of file float128.h.
|
inlineconstexprnoexcept |
Sets the upper 48 bits of the fraction, leaving the exponent and the sign alone.
| f | Fraction bits. Bits above the 48 the field holds are dropped. |
Definition at line 2042 of file float128.h.
|
inlineconstexprnoexcept |
Inverts the sign.
Definition at line 2046 of file float128.h.
|
inlineconstexprnoexcept |
Sets the sign.
Definition at line 2050 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
Gets the sign.
Definition at line 2054 of file float128.h.
|
inlineconstexprnoexcept |
Reads the raw binary128 encoding.
The counterpart of the float128(low, high) constructor: the two together are what a std::bit_cast to and from the storage would be, without needing the layout to be spelled out at the call site. Nothing is interpreted, so a NaN keeps its payload and a subnormal is not normalized - use get_components() for the value the encoding stands for.
| l | Receives the low QWORD (fraction bits 63:0) |
| h | Receives the high QWORD (sign, exponent, fraction bits 111:64) |
Definition at line 2066 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
Classifies the float128 value according to IEEE 754.
Definition at line 2075 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
Returns the exponent of the object - like the base 2 exponent of a floating point A value of 2.1 would return 1, values in the range [0.5,1.0) would return -1.
Definition at line 2097 of file float128.h.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
break the float into its components. Normalizes subnormal values
Forced open rather than merely offered for inlining, which is an exception to the rule stated on FP128_FORCE_INLINE: this has a body of its own, so it would otherwise be FP128_INLINE. The body is a handful of shifts and masks off the object's own bits, and every arithmetic operator and math function opens with two of these calls, so what the caller gains is not the call itself but the constant folding across it - the exponent and sign arithmetic that follows collapses only once the components are visible. Clang declined the invitation where MSVC accepted it, which is what made this measurable rather than academic: on 2026-08-15 clang-cl left this and the rounding step after the division (then norm_fraction_sticky(), now round_pack(), which is forced open for the same reason) out of line in operator/=, and float128 division measured 13.0 M/s against MSVC's 20.9 M/s.
| l | Reference to receive the low fraction |
| h | Reference to receive the high fraction |
| e | Reference to receive the unbiased exponent |
| s | Reference to receive the sign |
Definition at line 2129 of file float128.h.
|
inlinestaticconstexprnoexcept |
Shifts a significand and its extra word right, keeping a sticky record of what fell off.
The bits shifted out of the significand move into the top of extra, and whatever drops out of extra is jammed into its lowest bit rather than lost, so the word still tells an exact result, a tie and a value above the tie apart.
| l | Low QWORD of the significand |
| h | High QWORD of the significand |
| extra | Bits below the significand, left aligned |
| dist | Bits to shift, at least one |
Definition at line 2199 of file float128.h.
|
inlinestaticconstexprnoexcept |
Shifts a 128 bit value right, jamming any set bit that falls off into the lowest bit.
The alignment step of an addition: the shifted operand only has to be accurate to the bit below the guard bit of the sum, and a jammed lowest bit is enough to say there was more.
Forced open, as are shift_right_jam128_extra() and norm_round_pack(), which addition reaches through. Offered for inlining only, Clang kept all three out of line, the three outputs went through memory on every call, and float128 addition measured 95 M/s against 174 M/s inlined (P-core, 2026-10-05). MSVC inlined them either way.
| l | Low QWORD |
| h | High QWORD |
| dist | Bits to shift, at least one |
Definition at line 2243 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Whether rounding should add one unit in the last place.
| mode | Rounding direction |
| sign | Sign of the result |
| extra | Bits below the significand, left aligned and jammed |
Definition at line 2267 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
The slow half of round_pack(): results that overflow or are subnormal.
| sign | Sign of the result |
| exp | Biased exponent less one, as round_pack() computes it |
| l | Low QWORD of the significand |
| h | High QWORD of the significand |
| extra | Bits below the significand, left aligned and jammed |
| mode | Rounding direction |
Definition at line 2289 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Rounds an exact result once, in the current rounding direction, and encodes it.
The significand is added to the exponent field rather than merged into it: its leading one sits on the lowest exponent bit, which is why the exponent is passed in less one. That makes the carry of a significand that rounds up to the next power of two land in the exponent on its own, and the carry out of the largest finite value land on infinity.
| sign | Sign of the result |
| e | Unbiased exponent of bit 112 of the significand |
| l | Low QWORD of the significand |
| h | High QWORD of the significand. The leading one must be at bit 48: a zero significand is not accepted, the callers deal with an exact zero themselves. |
| extra | Bits below the significand, left aligned, with anything further down jammed into bit 0. Zero when the significand is exact. |
Definition at line 2342 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
| sign | Sign of the result |
| e | Unbiased exponent of bit 112 of the significand |
| l | Low QWORD of the significand |
| h | High QWORD of the significand, its leading one at bit 48 |
| extra | Bits below the significand, left aligned, the rest jammed into bit 0 |
| mode | Rounding direction to use instead of the current one |
Definition at line 2354 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Normalizes an exact non negative 128 bit significand and rounds it once.
For results whose leading one can be anywhere: a sum after cancellation, a remainder, a fraction. The value is (h:l) * 2^(e - 112).
| sign | Sign of the result |
| e | Exponent the value would have if its leading one were at bit 112 |
| l | Low QWORD |
| h | High QWORD |
| sticky | True when set bits below (h:l) were already dropped |
Definition at line 2388 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Builds a float128 from a 128 bit fraction, a value in [0,1).
The counterpart of reading a mantissa out with get_components(): log2() does its argument reduction and series on plain 128 bit fractions, and this is how the two results it ends up with re-enter floating point.
| low | Low QWORD of the fraction. |
| high | High QWORD of the fraction. |
Definition at line 2414 of file float128.h.
|
inlineconstexprnoexcept |
Stores a significand and exponent, rounding when the value is subnormal.
| l | Low part of the significand |
| h | High part of the significand, which must have its leading one at bit 48 (bit 112 of the whole) unless the significand is zero |
| e | Unbiased exponent, can be any value: one past the format's range produces an infinity, one below it a subnormal or a zero, rounded once in the current direction. |
| s | Sign (1 is negative) |
Definition at line 2430 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
x with its quiet bit set. The payload, and the sign, are kept.
Definition at line 2445 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
The result of an operation with a NaN operand (IEEE 754-2008 6.2).
A signaling NaN operand is the invalid operation. Either way the result is a quiet NaN, and the standard recommends it be one of the inputs so that a payload survives the computation: the first NaN operand is returned, quieted.
| a | First operand |
| b | Second operand |
Definition at line 2458 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2465 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 2472 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
The result of an invalid operation on non NaN operands, such as inf - inf or 0 / 0.
Definition at line 2483 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
The sign of an exact zero sum of two operands of opposite sign (IEEE 754-2008 6.3).
Definition at line 2493 of file float128.h.
|
inlinenodiscardconstexprnoexcept |
Expands the fraction part of this value into an exact fixed point number.
The result is the fraction scaled by 2^256 and held in four words, frac[0] being the least significant. Nothing is lost: a fraction bit of a binary128 has weight 2^(e-112) with e no smaller than -111 on the path that calls this, so scaling by 2^256 always lands on an integer, and the fraction is below one so the product stays under 2^256.
Printing the digits from this expansion is exact. Deriving them by repeatedly multiplying a float128 by 100000 instead, as this used to, rounds once per group and the error compounds over the eight or so groups that a full precision value needs.
| frac | Output, four words holding the fraction scaled by 2^256 |
Definition at line 2524 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Multiplies the fixed point fraction by a small value and returns the part that crossed the binary point.
| frac | Fraction scaled by 2^256, updated in place to hold the new fraction |
| mul | Multiplier, small enough that the result stays below 2^64 |
Definition at line 2579 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
True when every word of the fixed point fraction is zero.
Definition at line 2592 of file float128.h.
|
inlinestaticconstexprnoexcept |
Full 256 bit product of two 128 bit values.
| al | Low QWORD of the first operand |
| ah | High QWORD of the first operand |
| bl | Low QWORD of the second operand |
| bh | High QWORD of the second operand |
| res | Output, four words with res[0] the least significant |
Definition at line 2630 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Index of the highest set bit of a multi word value, or -1 when it is zero.
| a | Words, a[0] the least significant |
| words | Word count |
Definition at line 2658 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Writes a value into a zeroed accumulator, shifted to a given bit position.
A negative offset puts part or all of the value below the accumulator's least significant bit. Those bits are not representable there but still decide the rounding, so whether any of them was set is reported back rather than dropped.
| acc | Accumulator, must be zero on entry |
| src | Value to place, src[0] the least significant word |
| words | Word count of src |
| offset | Bit position the least significant bit of src lands on, may be negative |
Definition at line 2680 of file float128.h.
|
inlinestaticconstexprnoexcept |
Adds b into a. The accumulator is wide enough that the sum cannot carry out.
Definition at line 2723 of file float128.h.
|
inlinestaticconstexprnoexcept |
Subtracts b from a, which must not be smaller.
Definition at line 2731 of file float128.h.
|
inlinestaticconstexprnoexcept |
Subtracts one from the accumulator, which must not be zero.
Definition at line 2743 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Three way comparison of two accumulators.
Definition at line 2752 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Normalizes the product of two mantissas to bit 112, handing back the bits it drops.
The multiply and the square both arrive here with (h:l) equal to their 256 bit product shifted right by 111. Both operands were normalized to [2^112, 2^113), so the product is in [2^224, 2^226) and (h:l) is in [2^113, 2^115): its leading one is at bit 113 or bit 114 and nowhere else, which makes the remaining shift 1 or 2 and the choice a single bit test.
Nothing is rounded here. The bits shifted out, and the sticky bit for everything the caller dropped before them, are returned in the form round_pack() takes, so that the result is rounded once and to its final width - which for a subnormal product is narrower than 113 bits.
| l | Low part of the shifted product, replaced by the normalized fraction |
| h | High part of the shifted product, replaced by the normalized fraction |
| e | Unbiased exponent, adjusted to match the normalized fraction |
| sticky | True when the caller already dropped one or more set bits below l |
Definition at line 2779 of file float128.h.
Produces the closest value larger than x nextUp(x) is the least floating-point number in the format of x that compares greater than x. If x is the negative number of least magnitude in x’s format, nextUp(x) is −0. nextUp(±0) is the positive number of least magnitude in x’s format. nextUp(+∞) is +∞, and nextUp(−∞) is the finite negative number largest in magnitude. When x is NaN, then the result is according to 6.2. nextUp(x) is quiet except for sNaNs.
| x | Source value |
Definition at line 2800 of file float128.h.
Produces the closest value smaller than x.
| x | Source value |
Definition at line 2837 of file float128.h.
|
inlinestaticnodiscardconstexpr |
|
inlinestaticnodiscardconstexpr |
Return the quiet (non-signaling) NaN constant.
Definition at line 2879 of file float128.h.
|
inlinestaticnodiscardconstexpr |
Return a signaling NaN.
Nothing in the library raises an exception on encountering one - there is no floating point status to raise it in - but the encoding is distinguishable, which is what numeric_limits::signaling_NaN() and is_signaling() need.
Definition at line 2888 of file float128.h.
|
inlinestaticnodiscardconstexpr |
|
inlinestaticnodiscardconstexpr |
|
inlinestaticnodiscardconstexpr |
|
inlinestaticnodiscardconstexpr |
|
inlinestaticnodiscardconstexprnoexcept |
|
inlinestaticnodiscardconstexprnoexcept |
|
inlinestaticnodiscardconstexprnoexcept |
|
inlinestaticnodiscardconstexprnoexcept |
|
inlinestaticnodiscardconstexprnoexcept |
2*pi
Definition at line 2954 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
1/pi
Definition at line 2956 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
1/sqrt(pi)
Definition at line 2958 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Natural logarithm of 2.
Definition at line 2960 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Natural logarithm of 10.
Definition at line 2962 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Base 2 logarithm of e.
Definition at line 2964 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Base 10 logarithm of e.
Definition at line 2966 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Base 10 logarithm of 2.
Definition at line 2968 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Square root of 3.
Definition at line 2970 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
1/sqrt(3)
Definition at line 2972 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
The Euler-Mascheroni constant.
Definition at line 2974 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
The golden ratio.
Definition at line 2976 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Calculates 10^e.
Exact for 0 <= e <= 48, where 10^e is representable. Otherwise the power is formed in double word arithmetic - a pair (hi, lo) whose sum carries about 226 bits, the error of each product recovered exactly with fma() - and rounded once, at the end, in the current direction.
Measured against exact rationals for every e from -4970 to 4935 in all four rounding directions (2026-10-10): correctly rounded, with exactly the exception flags of a single rounding, everywhere except exp10(-4931) rounding upward, which is one ulp high. Close to the subnormal range the cross terms of the last products fall below the subnormal grid and are rounded there, which can cost the last bit; the bound is 1 ulp in every direction.
The previous version squared and multiplied the rounded 0.1 itself, carrying its error and every rounding along: exp10(-100) was 66 ulp off and exp10(-4000) 1809, and the directed modes drifted further still, up to 3453 ulp.
| e | Integer exponent. Beyond the range of the format the result overflows (e > 4932) or underflows (e < -4965) as rounding the exact power would, in the current direction and with the same exception flags. |
Definition at line 3000 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
The power of exp10(), for an e whose result is inside the range of the format.
Binary exponentiation on (hi, lo) pairs. The product of two pairs is hi * bh, whose rounding error fma() recovers exactly, plus the cross terms, which are 2^-113 of it and are rounded; the pair is then renormalized so that lo stays below an ulp of hi.
| e | Exponent, with 10^e inside the range of the format |
Definition at line 3023 of file float128.h.
|
inlinestaticnodiscardnoexcept |
exp10_double_word() at run time, raising only the exceptions the result justifies.
The cross terms of the products can underflow while the power itself does not.
| e | Exponent, with 10^e inside the range of the format |
Definition at line 3061 of file float128.h.
|
inlinestaticconstexpr |
Returns false; this type does not conform to IEEE 754-1985.
Definition at line 3068 of file float128.h.
|
inlinestaticconstexpr |
Whether the type conforms to IEEE 754-2008 (binary128).
The arithmetic, the conversions and the operations of clause 5 conform in every build, but the standard also requires the rounding-direction attributes of clause 4 and the status flags of clause 7, which exist only when FP128_IEEE_ENV is defined.
Definition at line 3078 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Rounds to an integral value (IEEE 754-2008 roundToIntegral, 5.3.1).
The shared engine of floor, ceil, trunc, round, rint and nearbyint, which differ only in the direction they round. It works on the encoding: the fraction bits below the units bit are cleared, and when the value has to move up one unit is added at the units bit, a carry out of the fraction landing in the exponent on its own. Nothing is subtracted, so nothing rounds, and the sign is left alone - a negative value that rounds to zero gives -0.
The previous implementations subtracted the fraction from the value, which made the zero results of a negative argument positive, and round() added one half and truncated, which rounded the largest value below one half up to one and 2^112 + 1 to 2^112 + 2.
| x | Value to round |
| mode | Direction, ignored when ties_away is set |
| ties_away | Round to nearest with ties away from zero instead, as round() does |
| signal_inexact | Raise the inexact exception when the result differs from x, which distinguishes roundToIntegralExact (rint) from the other five |
Definition at line 3448 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Converts an integral value to an integer type, the way the C rounding functions do.
| I | The integer type |
| x | An integral value, an infinity or a NaN |
Definition at line 3522 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Square of a 113 bit significand compared with a 256 bit value.
| rl | Low QWORD of the significand |
| rh | High QWORD of the significand |
| n | The value to compare against, n[0] the least significant word |
Definition at line 3838 of file float128.h.
e to the power of a reduced argument, |r| <= ln2/2.
| r | Reduced argument |
Definition at line 4160 of file float128.h.
|
inlinestaticnodiscardnoexcept |
a^n by repeated squaring, for a positive finite a.
A negative exponent inverts the power, unless the power overflowed or underflowed on its way there while its reciprocal would not have: then exp() and log() reach it directly.
| a | Base, positive and finite |
| n | Exponent |
Definition at line 4307 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
The arguments every logarithm treats alike (IEEE 754-2008 9.2.1).
A NaN propagates, a zero is a pole - the division by zero exception, and -inf - any other negative argument is the invalid operation, and +inf is its own logarithm. log2() used to return -inf for a negative argument, a finite value for +inf, and a finite value for a NaN.
| x | Argument |
| result | Receives the answer when there is one |
result holds the answer. Definition at line 4435 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Largest |t| the log1p_small() series is used for. Chosen so twelve terms suffice.
Definition at line 4458 of file float128.h.
Natural logarithm of 1+t for |t| <= 2^-4, accurate relative to the result.
log(1+t) = 2 * atanh(t / (2+t)). The substitution replaces the Mercator series in t, which would need a hundred terms at this precision, with one in s^2 where |s| < 2^-4.9, so twelve terms reach the last bit of the mantissa.
What matters more than the term count is that the result stays accurate relative to its own size. Near one the logarithm is proportional to t, and t reaches this function exactly - the subtraction that produced it cancelled two values within a factor of two of each other, which is exact. Computing the same thing as a difference of two numbers near one loses a bit for every power of two the argument sits closer to one: at t = 2^-60 barely half the mantissa survives.
| t | Offset from one, must satisfy |t| <= 2^-4 |
Definition at line 4479 of file float128.h.
|
inlinestaticnoexcept |
Exact sum of two values, as a rounded sum and the error it made.
Dekker's algorithm. Nothing here is an approximation: a + b is exactly sum + err for any two finite operands.
| a | First operand |
| b | Second operand |
| sum | Receives the rounded sum |
| err | Receives a + b - sum, exactly |
Definition at line 4884 of file float128.h.
|
inlinestaticnoexcept |
Exact sum of two values whose magnitudes are ordered.
| a | First operand, must not be smaller in magnitude than b |
| b | Second operand |
| sum | Receives the rounded sum |
| err | Receives a + b - sum, exactly |
Definition at line 4898 of file float128.h.
|
inlinestaticnodiscardnoexcept |
Nearest integer to x / (pi/2), the quadrant the argument falls in.
Beyond 2^62 the quadrant no longer fits in the integer the reduction counts with, and an argument that large has fewer bits below the binary point than a quadrant is wide - its sine is not determined by the value in any useful sense. Everything up to there reduces exactly, see reduce_half_pi().
| x | Argument, below 2^60 in magnitude; reduce_large() takes the larger ones |
Definition at line 4916 of file float128.h.
|
inlinestaticnoexcept |
Reduces an argument of any size: x = n * pi/2 + r, with |r| <= pi/4 (Payne and Hanek).
Subtracting multiples of a stored pi/2, as reduce_half_pi() does, needs the multiple n as an integer and pi/2 to as many bits as n has plus the 226 the residual keeps - out of reach once n runs to thousands of bits. Here x * 2/pi is formed instead, in integer arithmetic, from the 113 bit mantissa and a 384 bit window of the binary expansion of 2/pi chosen by the exponent. The bits of 2/pi above the window only add multiples of four to the product, which leave the quadrant where it is; the bits below it only reach past the fraction the window keeps.
That fraction has 380 bits or more, which leaves 226 significant ones even when x is closer to a multiple of pi/2 than any binary128 argument can be: for a random argument the fraction leads with about as many zero bits as the logarithm of the count of binary128 values, 127. Rounded to the nearest quadrant and multiplied by pi/2, it becomes the residual.
Before this existed sin(), cos() and tan() reduced nothing above 2^62, and returned values such as 2^3240 for sin(1.5e21). Above 2^321 the series they evaluated never terminated.
| x | Argument, finite and non zero |
| hi | Receives the residual |
| lo | Receives what did not fit in hi |
Definition at line 4948 of file float128.h.
|
inlinestaticnoexcept |
Reduces x to [-pi/4, pi/4], as an unevaluated sum, and returns the quadrant.
| x | Argument, finite |
| hi | Receives the residual |
| lo | Receives what did not fit in hi |
Definition at line 5082 of file float128.h.
|
inlinestaticnoexcept |
Subtracts n*(pi/2) from x, leaving the residual as an unevaluated sum.
pi/2 is irrational, so no single float128 multiple of it can be subtracted without leaving an error of n ulp behind - and the sine of the residual is only as accurate as the residual itself. Where the answer is small, which is exactly where an argument lands near a multiple of pi/2, that error is the whole answer: sin() used to return a value with 55 correct bits for an argument a few ulp away from pi.
Two things fix it. pi/2 is carried in three pieces covering 342 bits rather than 113, and each product n*piece is split into its rounded value and its exact error with fma(), so no multiplication is lost either. The residual accumulates as a pair, giving it 226 bits.
| x | Argument |
| n | Multiple of pi/2 to remove |
| hi | Receives the residual |
| lo | Receives what did not fit in hi |
Definition at line 5113 of file float128.h.
|
inlineconstexprnoexcept |
The encoding as a key whose unsigned order is the total order of IEEE 754-2008 5.10.
Positive encodings already ascend with their value, NaNs above infinity and quiet NaNs above signaling ones; negative encodings descend. Flipping every bit of a negative encoding and only the sign bit of a positive one puts the whole range in one ascending sequence.
Definition at line 6041 of file float128.h.
|
inlinestaticnodiscardconstexprnoexcept |
True when x is an integer whose last place is one, which is the parity a tie needs.
Definition at line 6140 of file float128.h.
|
inlinestaticnodiscardnoexcept |
|x| mod |y|, along with the low bits of the quotient it implies.
The shared engine behind fmod, remainder and remquo. All three are exact operations on the mantissas, and all three need the same long division; only what they do with the quotient differs.
| x | Dividend, must be finite and non zero |
| y | Divisor, must be finite and non zero |
| quotient | Receives the low bits of the integer quotient |
| half | Receives how twice the remainder compares with |y|: negative, zero or positive. remainder() decides on it, and it is decided here, on the integer mantissas, because doubling the remainder in floating point overflows once |y| is above half the largest finite value. |
Definition at line 6235 of file float128.h.
lgamma(2 + z) for |z| <= 1/2, accurate relative to the result.
The Taylor series of log(gamma) about 2:
inf k zeta(k) - 1 k
lgamma(2 + z) = (1 - gamma) z + sum (-1) ----------- z
k=2 k
zeta(k) - 1 is about 2^-k, so a term is about (z/2)^k / k and 58 of them reach past the last bit for |z| <= 1/2. Every term carries a power of z, so the sum is accurate relative to itself however close z is to zero - which is what lgamma near its zeros at 1 and 2 needs, and what the recurrence and Stirling series it replaced there could not give: they formed the answer as a difference of two values near 80, 2^-106 wide in absolute terms, which was 2^28 ulp at lgamma(1 + 2^-20) and every bit of lgamma(2 - 2^-100).
The coefficients are the series' own, rounded to binary128 (ties to even) from mpmath at 400 bits; the first is 1 - gamma, gamma being Euler's constant.
| z | Offset from two, |z| <= 1/2 |
Definition at line 6418 of file float128.h.
|sin(pi * x)| for a finite x that is not an integer, without the error of rounding pi * x.
The integer part of x only changes the sign, and x - round(x) is exact, so the reduction costs nothing. What is left, f in [-1/2, 1/2], is multiplied by pi as an unevaluated sum: the rounded product, its exact error from fma(), and the part of pi below the last place of float128::pi(). sin(pi * f) is then sin(p) + cos(p) * e to well past the last bit. Forming sin(pi() * x) instead, as lgamma() did, rounded the argument before reducing it: next to a pole, where the sine is as small as x is close to an integer, that rounding was most of the answer.
| x | Finite value, not an integer, below 2^112 in magnitude |
Definition at line 6500 of file float128.h.
|
friend |
Definition at line 675 of file float128.h.
Adds 2 values and returns the result.
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 3105 of file float128.h.
subtracts the right hand side operand to this object to and returns the result.
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 3116 of file float128.h.
Multiplies the right hand side operand with this object to and returns the result.
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 3127 of file float128.h.
Divides this object by the right hand side operand and returns the result.
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 3138 of file float128.h.
|
friend |
Adds a scalar and a float128, in that order.
| lhs | Left operand |
| rhs | Right operand |
Definition at line 3157 of file float128.h.
|
friend |
Subtracts a float128 from a scalar.
| lhs | Left operand |
| rhs | Right operand |
Definition at line 3164 of file float128.h.
|
friend |
Multiplies a scalar and a float128, in that order.
| lhs | Left operand |
| rhs | Right operand |
Definition at line 3171 of file float128.h.
|
friend |
Divides a scalar by a float128.
| lhs | Left operand |
| rhs | Right operand |
Definition at line 3178 of file float128.h.
|
friend |
Shifts a scalar left by a float128 shift count, scaling it by a power of two.
The left operand is widened to float128 first, so the result is 128 bit rather than the builtin type of lhs.
The count is rhs converted to int32_t, the same conversion the float128 on the left overload applies, and that conversion truncates, so a count of 3.75 shifts by 3 - as it does in fixed_point128, whose conversion is a plain shift.
| lhs | Left operand, the value being shifted |
| rhs | Right operand, the shift count |
Definition at line 3198 of file float128.h.
|
friend |
Shifts a scalar right by a float128 shift count, scaling it by a power of two. The left operand is widened to float128 first, see operator<< above.
| lhs | Left operand, the value being shifted |
| rhs | Right operand, the shift count |
Definition at line 3211 of file float128.h.
Compare logical/bitwise equal.
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 3226 of file float128.h.
|
friend |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 3247 of file float128.h.
|
friend |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 3252 of file float128.h.
Return true when objects are not equal. Can be used as logical XOR.
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 3262 of file float128.h.
|
friend |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 3267 of file float128.h.
|
friend |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Return true when objects are not equal. Can be used as logical XOR.
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 3272 of file float128.h.
Return true if this object is small than the other.
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 3279 of file float128.h.
|
friend |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 3308 of file float128.h.
|
friend |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 3311 of file float128.h.
Return true this object is small or equal than the other.
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 3318 of file float128.h.
|
friend |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 3330 of file float128.h.
|
friend |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 3333 of file float128.h.
Return true this object is larger than the other.
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 3340 of file float128.h.
|
friend |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 3368 of file float128.h.
|
friend |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 3371 of file float128.h.
Return true this object is larger or equal than the other.
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 3378 of file float128.h.
|
friend |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 3389 of file float128.h.
|
friend |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 3392 of file float128.h.
Return the NaN constant.
Definition at line 3399 of file float128.h.
|
friend |
Tests if the value is a NaN.
| x | Value to test |
Definition at line 3405 of file float128.h.
|
friend |
Tests if the value is an Infinite (negative or positive)
| x | Value to test |
Definition at line 3415 of file float128.h.
Returns the absolute value of x.
| x | Input value |
Definition at line 3422 of file float128.h.
Performs the floor() function, similar to libc's floor(), rounds down towards -infinity.
| x | Input value |
Definition at line 3536 of file float128.h.
Performs the ceil() function, similar to libc's ceil(), rounds up towards infinity.
| x | Input value |
Definition at line 3545 of file float128.h.
Rounds towards zero.
| x | Value to truncate |
Definition at line 3554 of file float128.h.
Rounds towards the nearest integer. The halfway value (0.5) is rounded away from zero.
| x | Value to round |
Definition at line 3564 of file float128.h.
|
friend |
Rounds x to an integer in the current rounding direction and returns it as int64_t.
| x | Input value |
Definition at line 3575 of file float128.h.
|
friend |
Rounds towards the nearest integer. The halfway value (0.5) is rounded away from zero.
| x | Value to round |
Definition at line 3583 of file float128.h.
|
friend |
Rounds x to an integer in the current rounding direction and returns it as int32_t.
| x | Input value |
Definition at line 3589 of file float128.h.
|
friend |
Rounds towards the nearest integer. The halfway value (0.5) is rounded away from zero.
| x | Value to round |
Definition at line 3597 of file float128.h.
|
friend |
Retrieves an integer that represents the base-2 exponent of the specified value.
IEEE 754-2008 logB (5.3.3) with an integer result format: a zero, an infinity and a NaN have no exponent the result can express, so each is the invalid operation.
| x | The specified value. |
Definition at line 3609 of file float128.h.
returns the value of x with the sign of y.
| x | The value that's returned as the magnitude of the result. |
| y | The sign of the result. |
Definition at line 3633 of file float128.h.
Performs the fmod() function, similar to libc's fmod(), returns the remainder of a division x/root.
| x | Numerator |
| y | Denominator |
Definition at line 3645 of file float128.h.
Split into integer and fraction parts. Both results carry the sign of the input variable.
| x | Input value |
| iptr | Pointer to float128 holding the integer part of x. |
Definition at line 3720 of file float128.h.
Determines the positive difference between the first and second values.
| x | First value |
| y | Second value |
Definition at line 3745 of file float128.h.
Returns the minimum between x and y.
| x | First value |
| y | Second value |
Definition at line 3757 of file float128.h.
Returns the maximum between x and y.
| x | First value |
| y | Second value |
Definition at line 3781 of file float128.h.
Calculates the hypotenuse. i.e. sqrt(x^2 + y^2)
| x | First value |
| y | Second value |
Definition at line 3799 of file float128.h.
Calculates the square of a value. i.e. x^2.
Faster than x * x and identical to it, see float128::square().
| x | Value to square |
Definition at line 3830 of file float128.h.
Calculates the square root, correctly rounded.
IEEE 754 requires the square root to be correctly rounded, the same as the four arithmetic operations, and Newton's method alone cannot promise that: every step rounds, and the last one can land a unit either side of the answer. It used to, for a quarter of all arguments.
So Newton's method only gets close, and the last bit is then settled exactly. The mantissa m (doubled when the exponent is odd, so that what is left of it halves exactly) is in [2^112, 2^114), which puts the square root of N = m * 2^112 in [2^112, 2^113) - exactly the 113 bit significand the result needs. Squaring a candidate r in integer arithmetic and comparing with N moves it onto floor(sqrt(N)), and the remainder N - r*r then says which way to round: the root is past the halfway point r + 1/2 exactly when the remainder exceeds r, and it can never sit on it, because (r + 1/2)^2 is not an integer.
Based on the book "Math toolkit for real time programming" by Jack W. Crenshaw.
| x | Value to calculate the root of |
| iterations | Ignored. The result is correctly rounded whatever its value; the parameter is kept so that existing calls still compile. |
Definition at line 3872 of file float128.h.
Calculates the cube root. Uses the Halley's method.
| x | Floating point value |
| iterations | how many Halley to perform, usually 1 is enough |
Definition at line 3958 of file float128.h.
Calculates the reciprocal of a value, 1 / x, correctly rounded.
The division itself, which rounds once in the current direction. This used to refine a double seed with Newton iterations, which was a third of the speed of the division (11 M/s against 35 M/s on MSVC, 10.5 against 37 on Clang, P-core, 2026-10-10) and up to an ulp off: a subnormal result was rounded twice, and in a directed rounding mode the result could land on the wrong side.
| x | Input value |
Definition at line 4017 of file float128.h.
|
friend |
Factorial reciprocal (inverse). Calculates 1 / x! Maximum supported value of x is 50.
| x | Input value |
| res | Result of the function |
Definition at line 4029 of file float128.h.
|
friend |
Returns the double factorial of a number, x!! = x * (x - 2) * (x - 4) * ...
The values below 100 come from a table built during compilation, every product rounded to nearest. Filling a function local table on first use, as this used to, was a data race when two threads made the first call together, and under FP128_IEEE_ENV the products took the rounding direction of whichever caller came first.
| x | The number to compute the double factorial of. |
< c[i] is i!!
Definition at line 4109 of file float128.h.
Computes e to the power of x.
x is written as k*ln2 + r with k an integer and |r| <= ln2/2, which turns the answer into 2^k * exp(r): the power of two is an exact scaling and only the reduced argument goes through a series.
The reduction is where the accuracy of the whole function is decided. ln2 is irrational, so k*ln2 cannot be represented and subtracting a rounded one leaves an error of k ulp - at the top of the range k reaches 16000 and fourteen bits of the answer are gone before the series even starts. Splitting ln2 into a high part whose low 14 bits are zero, so that k times it is exact, and a low part carrying the rest, keeps r accurate to far below its last bit.
The previous implementation raised e to the integer part by repeated squaring, which doubles its own error at every step, and reached the negative half of the range through reciprocal().
| x | A number specifying a power. |
Definition at line 4190 of file float128.h.
Computes 2 to the power of x.
| x | Exponent value |
Definition at line 4232 of file float128.h.
Calculates the exponent of x and reduces 1 from the result: (e^x) - 1.
| x | A number specifying a power. |
Definition at line 4269 of file float128.h.
Computes x to the power of y (IEEE 754-2008 pown)
| x | Base value |
| y | Exponent value (integer) |
Definition at line 4333 of file float128.h.
Computes x to the power of y.
The special values follow IEEE 754-2008 9.2.1 throughout. Among those the previous version got wrong: pow(0.5, inf) and pow(2, -inf) were infinite rather than zero, pow(2, NaN) was infinite, pow(-0, 0.5) a NaN, and every integer exponent beyond 11355 in magnitude overflowed whatever the base, so pow(1 + 2^-40, 12000), which is about 1.00000001, came out infinite.
Accuracy, measured against mpmath and pinned by tests/float128_accuracy_gtest.cpp: within 4 + 2.5 |y log2(x)| ulp, which is about 41000 ulp next to the overflow and underflow thresholds, where |y log2(x)| reaches 16383. Both methods below lose about two ulp per unit of that product - the relative error of log(x), or of every squaring, becomes an absolute error of the exponent, and the exponential makes it relative again - and holding it to a few ulp would take an intermediate wider than 113 bits. A y of 1/2 is the square root, correctly rounded.
| x | Base value |
| y | Exponent value |
Definition at line 4359 of file float128.h.
Calculates the natural Log (base e) of x: log(x)
| x | The number to perform log on. |
Definition at line 4513 of file float128.h.
Calculates the Log base 2 of x: y = log2(x)
Accurate relative to its own result, which matters most for an argument close to one: the answer is then proportional to x - 1, and that difference is carried through exactly rather than being rounded onto a grid it would barely register on. That holds on both sides of one; below it the exponent is -1, and the answer is formed without the -1 that would cancel. The earlier implementation built the answer as a fixed point fraction of 112 bits before returning it as a float, which left log2(1 + 2^-112) with no correct significant bits at all.
| x | The number to perform log2 on. |
Definition at line 4542 of file float128.h.
Calculates Log base 10 of x: log10(x)
| x | The number to perform log on. |
Definition at line 4700 of file float128.h.
Calculates Log base 2 of x as an integer ignoring the sign of x. Similar to: floor(log2(fabs(x)))
| x | The number to perform log on. |
Definition at line 4720 of file float128.h.
Calculates the natural Log (base e) of 1 + x: log(1 + x)
| x | The number to perform log on. |
Definition at line 4744 of file float128.h.
Calculate the sine function over a limited range [-0.5pi, 0.5pi] Using the Maclaurin series expansion, the formula is: x^3 x^5 x^7 sin(x) = x - — + — - — + ... 3! 5! 7!
| x | value in Radians in the range [-0.5pi, 0.5pi] |
Definition at line 4790 of file float128.h.
Calculate the cosine function over a limited range [-0.5pi, 0.5pi].
Up to pi/4, the range the trigonometric functions reduce their argument to, the Maclaurin series is evaluated as one minus its tail:
2 4 6
x x x
cos(x) = 1 - ( — - ( — - ( — - ...))) 2! 4! 6!
The tail is at most 0.3 and is formed from the argument alone, so it carries its own last bits and the subtraction from one rounds once. A zero argument gives exactly one, and so does any argument whose square is below the last place of one. This used to be computed as sin1(pi/2 - x), whose series sums to 1 - 2^-113 for x = 0: cos(0) and sin(pi/2) were not one.
Beyond pi/4 the cosine is the sine of the complement, which stays accurate near pi/2 where the series above would cancel down to nothing.
| x | value in Radians in the range [-0.5pi, 0.5pi] |
Definition at line 4839 of file float128.h.
Definition at line 5140 of file float128.h.
Calculate the inverse sine function.
asin(x) = atan(x / sqrt((1-x)(1+x))). The Newton iteration on sin() this replaced divided by cos(), the derivative, which vanishes at the ends of the domain: it converged slowly there, to about 58 correct bits at asin(1). Near the ends 1-x is exact, so the argument of atan() keeps its accuracy however close to one x gets.
| x | value in the range [-1,1] |
Definition at line 5177 of file float128.h.
Calculate the cosine function Ultimately uses sin1() with a reduced range of [-pi/4, pi/4] Sine's Maclaurin series converges faster than Cosine's.
| x | value in Radians |
Definition at line 5210 of file float128.h.
Calculate the inverse cosine function.
acos(x) = 2 * atan(sqrt((1-x)/(1+x))). The Newton iteration this replaced divided by sin(), which is zero at acos(1): that returned a NaN, and so did acos(1 - 2^-100). Near x = 1 the difference 1-x is exact, and near x = -1 the sum 1+x is, so the quotient keeps its accuracy at both ends.
| x | value in the range [-1,1] |
Definition at line 5245 of file float128.h.
Calculate the tangent function tan(x) = sin(x)/cos(x)
| x | value |
Definition at line 5267 of file float128.h.
Calculate the inverse tangent function.
| x | value |
Definition at line 5273 of file float128.h.
Calculate the inverse tangent function of the ratio y / x.
| y | value |
| x | value |
Definition at line 5339 of file float128.h.
Calculate the hyperbolic sine function Use the exponent function which produces more accurate results than the power series. e^x - e^(-x) sinh(x) = ---------— 2.
| x | value |
Definition at line 5393 of file float128.h.
Calculates the inverse hyperbolic sine For positive x: asinh(x) = log(x + sqrt(x^2 + 1)) For negative x, the function returns the result with the sign inverted.
| x | value |
Definition at line 5429 of file float128.h.
Calculate the hyperbolic cosine function over a limited range [-0.5pi, 0.5pi] e^x + e^(-x) cosh(x) = ---------— 2.
| x | value in Radians in the range [-0.5pi, 0.5pi] |
Definition at line 5474 of file float128.h.
Calculates the inverse hyperbolic cosine For x >= 1: acosh(x) = log(x + sqrt(x^2 - 1)) For x < 1, the function return zero.
| x | value in the range [1, inf] |
Definition at line 5498 of file float128.h.
Calculates the hyperbolic tangent e^x - e^(-x) tanh(x) = ---------— e^x + e^(-x)
| x | value |
Definition at line 5533 of file float128.h.
Calculates the inverse hyperbolic tangent 1 + x atanh(x) = 0.5 * log( --—) 1 - x.
| x | value in the range (-1, 1) |
Definition at line 5569 of file float128.h.
|
friend |
Calculates the Maclaurin series constants for the erf function. The array will hold 1 / (n! * (2n + 1))
| a | pointer to array that receives the results. The array must be preallocated. |
| count | Element count in the array |
Definition at line 5607 of file float128.h.
Computes the error function of a value. The erf function return a value in the range -1.0 to 1.0. There's no error return.
| x | A floating-point value. |
Definition at line 5626 of file float128.h.
Computes the complementary error function, 1 - erf(x).
Above one the answer is a small difference of two values close to one, so it cannot be reached through erf() - at x = 6 the subtraction would leave 55 of the 113 bits, and past 13 nothing at all. It is computed directly instead, from Laplace's continued fraction
2
-x
e 1
erfc(x) = ---------- * ------------------------
sqrt(pi) x + (1/2)/(x + 1/(x + ...))
evaluated with the modified Lentz algorithm. The fraction converges for every x above one, and fastest where the series form is weakest.
Accuracy, measured against mpmath and pinned by tests/float128_accuracy_gtest.cpp: within 56 ulp. The worst is just above one, 43 ulp at 1.32, where the fraction converges slowest and rounds once per step; from 2 on the error was measured below 28 ulp, and below one, where the answer is 1 - erf(x), below 8.
| x | Input value |
Definition at line 5708 of file float128.h.
|
friend |
Tests whether x is finite (not infinite and not NaN).
| x | Input value |
Definition at line 5765 of file float128.h.
Computes (x * y) + z with a single rounding at the end.
The whole point of a fused multiply add is that the product is not rounded before the addend reaches it, which is what makes the result correct to the last bit and what lets a caller recover the error of a multiplication as fma(x, y, -x*y). Writing it as x * y + z rounds twice and loses everything the addend cancels against.
The exact product of the two 113 bit mantissas is 226 bits, and the addend is another 113. Both are placed in a wide accumulator with their leading bits aligned, added or subtracted there, and the single rounding is applied when the result is read back out. An operand too far below the other one to reach the accumulator cannot change any bit of the result except through the tie break, so it is folded into the sticky bit.
| x | The first value to multiply. |
| y | The second value to multiply. |
| z | The value to add to the product. |
Definition at line 5785 of file float128.h.
Gets the mantissa and exponent of a floating-point number.
| x | Floating-point value. |
| expptr | Receives the exponent: zero for a zero, an infinity or a NaN. |
Definition at line 5923 of file float128.h.
Multiplies a floating-point number by an integral power of two.
| x | Floating-point value. |
| exp | Integer exponent. |
Definition at line 5948 of file float128.h.
|
friend |
True when the sign bit is set, including for -0 and for a negative NaN.
Definition at line 5971 of file float128.h.
|
friend |
True when x is neither zero, subnormal, infinite nor NaN.
Definition at line 5973 of file float128.h.
|
friend |
One of FP_NAN, FP_INFINITE, FP_ZERO, FP_SUBNORMAL or FP_NORMAL.
Definition at line 5975 of file float128.h.
True when either operand is a NaN, so that the two do not compare in any order.
This and the five predicates below are IEEE 754-2008's quiet comparisons (5.11): a quiet NaN operand is an ordinary unordered answer, a signaling one is the invalid operation. The relational operators are the signaling comparisons instead, which raise invalid for any NaN. The five below decide unorderedness through this function, which is where the signal comes from.
Definition at line 5993 of file float128.h.
x > y, false rather than unordered when either is a NaN.
Definition at line 6000 of file float128.h.
x >= y, false when either is a NaN.
Definition at line 6005 of file float128.h.
x < y, false when either is a NaN.
Definition at line 6010 of file float128.h.
x <= y, false when either is a NaN.
Definition at line 6015 of file float128.h.
x < y or x > y, false when either is a NaN.
Definition at line 6020 of file float128.h.
totalOrder(x, y): true when x precedes y, or equals it, in the IEEE 754 total order.
The order every value takes part in, NaNs included: -NaN < -inf < negative values < -0 < +0 < positive values < +inf < +NaN, a signaling NaN before a quiet one of the same sign, and NaNs of the same kind ordered by payload. It never signals, even for a signaling NaN.
| x | First value |
| y | Second value |
Definition at line 6059 of file float128.h.
totalOrderMag(x, y): totalorder() of the absolute values.
Definition at line 6067 of file float128.h.
maxNumMag: whichever of x and y has the larger magnitude, or fmax() when they tie.
| x | First value |
| y | Second value |
Definition at line 6079 of file float128.h.
minNumMag: whichever of x and y has the smaller magnitude, or fmin() when they tie.
| x | First value |
| y | Second value |
Definition at line 6092 of file float128.h.
|
friend |
isCanonical: always true, every binary128 encoding is canonical.
Definition at line 6105 of file float128.h.
|
friend |
isSignaling: true for a signaling NaN.
Definition at line 6107 of file float128.h.
|
friend |
isSubnormal: true for a subnormal value, which zero is not.
Definition at line 6109 of file float128.h.
|
friend |
isZero: true for either zero.
Definition at line 6111 of file float128.h.
|
friend |
A quiet NaN carrying the payload spelled out in the argument.
Mirrors the C library's nan(): the string is read as an unsigned integer, decimal by default, hexadecimal after an 0x prefix, and its low bits become the NaN's fraction. An empty or unparsable string gives the default NaN.
| payload | Digits of the payload, may be empty |
The only one of these that a call cannot reach through argument dependent lookup: its argument is a plain character pointer, so the name has to be visible at namespace scope - and a call has to be qualified as fp128::nan(...) wherever <cmath> puts its own nan(const char*) in scope too.
Definition at line 6124 of file float128.h.
x rounded to an integral value in the current direction, raising inexact when that changes it.
Definition at line 6165 of file float128.h.
x rounded to an integral value in the current direction.
Definition at line 6170 of file float128.h.
x * 2^n, the same operation ldexp performs.
Definition at line 6181 of file float128.h.
x * 2^n for a long exponent, clamped to what the format can reach.
Definition at line 6183 of file float128.h.
The representable value next to x in the direction of y.
A quiet operation, like IEEE 754-2008's nextUp and nextDown that it is built on: stepping from the largest finite value to infinity, or into the subnormal range or onto zero, raises neither overflow nor underflow (C's Annex F would raise them). Only a signaling NaN operand raises an exception, invalid, and is quieted.
| x | Starting value |
| y | Value giving the direction |
Definition at line 6205 of file float128.h.
The neighbour of x towards y. The same as nextafter: there is no wider type to convert from.
Definition at line 6214 of file float128.h.
IEEE 754 remainder: x - n*y with n the quotient rounded to the nearest even integer.
Unlike fmod, whose result keeps the sign of x, this one lands in [-|y|/2, |y|/2].
| x | Dividend |
| y | Divisor |
Definition at line 6305 of file float128.h.
The IEEE remainder together with the low bits of the quotient.
| x | Dividend |
| y | Divisor |
| quo | Receives at least the low three bits of the quotient, with the sign of x/y |
Definition at line 6318 of file float128.h.
Length of the diagonal of a box, computed without an intermediate overflow.
| x | First side |
| y | Second side |
| z | Third side |
Definition at line 6365 of file float128.h.
Natural logarithm of the absolute value of the gamma function.
Three regimes:
The result is the logarithm of the absolute value: the gamma function alternates sign between the poles at the non positive integers.
Accuracy, measured against mpmath and pinned by tests/float128_accuracy_gtest.cpp: within 6 ulp for x > 0. For x < 0 within the larger of 6 ulp and an absolute error of 2^-110. The absolute term matters next to the zeros lgamma has on the negative axis - two between each pair of poles from (-3, -2) to (-32, -31), about 1/n! from the poles - where the answer is a difference of terms of order log(n!): relative to a result that vanishes there it is unbounded.
| x | Input value |
Definition at line 6534 of file float128.h.
The gamma function.
Accuracy, measured against mpmath and pinned by tests/float128_accuracy_gtest.cpp: exact for the integers up to 38, within 8 ulp for |x| < 32, and within 8 + 4.5 |lgamma(x)| ulp beyond that, which reaches about 51000 ulp at either end of the range.
| x | Input value |
Definition at line 6626 of file float128.h.
Absolute value, the name <cmath> gives the floating point overload alongside fabs.
Definition at line 6690 of file float128.h.
|
friend |
User-defined literal implementation for constructing float128 from a string.
Definition at line 6693 of file float128.h.
| uint64_t fp128::float128::low |
Lower 64 bits of the float128 encoding.
Definition at line 721 of file float128.h.
| uint64_t fp128::float128::high |
Upper 64 bits (raw).
Definition at line 723 of file float128.h.
| _float128_bits fp128::float128::high_bits |
Upper 64 bits (bit-field view).
Definition at line 724 of file float128.h.
|
staticconstexpr |
Largest scaling a shift or ldexp() ever needs: enough to take the largest finite value below half the smallest subnormal, or the smallest subnormal above the largest finite value. Larger counts are clamped to it, which keeps the exponent arithmetic in range.
Definition at line 1367 of file float128.h.
|
staticconstexpr |
Number of Mercator series terms log2() needs.
The reduction leaves |z| <= 2^-6, so term n is bounded by 2^(-6n), and the series is cut off once that is below the last bit of a 113 bit mantissa with eight bits to spare.
Definition at line 2165 of file float128.h.
|
staticconstexpr |
The largest finite magnitude's significand, high QWORD, with its leading one at bit 48.
Definition at line 2277 of file float128.h.
|
staticconstexpr |
Normalize the fraction so the msb (unity bit) is on bit 112. The fraction value must contain the unity value The exponent component is adjusted based on the bit shift direction required.
| l | Low part of the fraction |
| h | High part of the fraction |
| e | Unbiased exponent, can be any value. |
Word count of the fixed point expansion used to print the fraction digits.
Definition at line 2507 of file float128.h.
|
staticconstexpr |
Words in the accumulator.
Definition at line 2614 of file float128.h.
|
staticconstexpr |
Bits in the accumulator.
Definition at line 2615 of file float128.h.
|
staticconstexpr |
Bit the leading one of the larger operand is placed on.
One below the top, so that adding two operands of the same magnitude cannot carry out of the accumulator.
Definition at line 2620 of file float128.h.
|
staticconstexpr |
Calculates the exponent of x: e Using the Maclaurin series expansion, the formula is: 1 2 3 x x x exp(x) = 1 + — + — + — + ... 1! 2! 3!
x
The Maclaurin series will quickly overflow as x's power increases rapidly. x ix fx Using the equality e = e * e Where ix is the integer part of x and fx is the fraction part. ix is computed via multiplications which won't overflow if the result value can be held. fx is computed via Maclaurin series expansion, but since fx < 1, it won't overflow.
| x | A number specifying a power. |
Terms of the Maclaurin series exp_reduced() runs. |r| <= ln2/2, so r^28/28! is past the last bit.
Definition at line 4153 of file float128.h.
|
staticconstexpr |
Terms of the log1p_small() series. |s| stays below 2^-4.9, so s^24 is past the last bit.
Definition at line 4460 of file float128.h.
|
staticconstexpr |
Terms of the cosine series cos1() runs. Up to pi/4, x^32/32! is below 2^-125.
Definition at line 4815 of file float128.h.
|
staticconstexpr |
Terms of the Stirling series lgamma() runs. Sixteen reach 2^-119 for an argument of 32.
Definition at line 6390 of file float128.h.
|
staticconstexpr |
Terms of the series lgamma_near_two() runs. For |z| <= 1/2 the last is below 2^-120 of the sum.
Definition at line 6392 of file float128.h.
|
staticconstexpr |
Below this magnitude lgamma() and tgamma() move the argument next to two by the recurrence.
Definition at line 6394 of file float128.h.