|
fixed_point128 1.0.1.0
128 bit integer, fixed point and floating point arithmetic for C++20
|
Google test class (friend). More...
#include <fixed_point128.h>
Public Types | |
| typedef fixed_point128< I > | type |
| Self type alias. | |
| typedef fixed_point128< I > * | ptr_type |
| Pointer type alias. | |
| typedef fixed_point128< I > & | ref_type |
| Reference type alias. | |
Public Member Functions | |
| constexpr void | get_components (uint64_t &l, uint64_t &h) const noexcept |
| Reads the raw representation: the two QWORDs of the 128 bit two's complement value. | |
Constructors | |
| constexpr | fixed_point128 () noexcept |
| Default constructor, creates an instance with a value of zero. | |
| constexpr | fixed_point128 (const fixed_point128 &rhs) noexcept |
| Copy constructor. | |
| template<int32_t I2> | |
| constexpr | fixed_point128 (const fixed_point128< I2 > &rhs) noexcept |
| cross-template Copy constructor, can be used between two different fixed_point128 templates A value too large for the destination wraps silently, as everywhere else in this class. Fraction bits the destination cannot hold are rounded to nearest, a tie going away from zero. | |
| constexpr | fixed_point128 (fixed_point128 &&rhs) noexcept |
| Move constructor Doesn't modify the right hand side object. Acts like a copy constructor. | |
| constexpr | fixed_point128 (double x) noexcept |
| Constructor from the double type Underflow goes to zero. Overflow, NaN and +-INF saturate to the extreme value carrying the sign of the input: max() for a positive one and lowest() for a negative one. Not constexpr: the exponent and mantissa are read through the Double union, and reading the inactive member of a union is not allowed during constant evaluation. | |
| constexpr | fixed_point128 (uint64_t x) noexcept |
| Constructor from uint64_t type A value of 2^I or above overflows into the sign and wraps silently. | |
| constexpr | fixed_point128 (int64_t x) noexcept |
| Constructor from int64_t type The shift is done in the unsigned domain, where it wraps rather than overflowing, and a negative value carries its sign bits along with it: scaling a two's complement value by a power of two is the same left shift its magnitude needs. | |
| constexpr | fixed_point128 (uint32_t x) noexcept |
| Constructor from uint32_t type. | |
| constexpr | fixed_point128 (int32_t x) noexcept |
| Constructor from int32_t type. | |
| fixed_point128 (const char *x) noexcept | |
| Constructor from const char* (C string). | |
| fixed_point128 (const std::string &x) noexcept | |
| Constructor from std::string. Accurate to 37 digits after the decimal point. Allows creating very high precision values. Much slower than the rhs constructors. | |
| constexpr | fixed_point128 (uint64_t l, uint64_t h) noexcept |
| Constructor from the two QWORDs of the raw value, useful for creating very small constants. The pair is read as a 128 bit two's complement integer scaled by 2^-F, so a negative value is spelled with the MSB of h set rather than with a separate sign. | |
| constexpr | ~fixed_point128 () noexcept=default |
| Destructor. | |
| constexpr fixed_point128 & | operator= (const fixed_point128 &rhs) noexcept |
| Assignment operator. | |
| constexpr fixed_point128 & | operator= (fixed_point128 &&rhs) noexcept |
| Move assignment operator. | |
| template<int32_t I2> | |
| constexpr fixed_point128< I > & | operator= (const fixed_point128< I2 > &rhs) noexcept |
| cross-template assignment operator, can be used between two different fixed_point128 templates Behaves as the cross-template constructor: a value too large for this instantiation wraps, and fraction bits it cannot hold are rounded to nearest, a tie going away from zero. | |
Conversion Operators | |
| constexpr | operator int64_t () const noexcept |
| operator int64_t - converts to a int64_t The fraction is truncated towards zero, as the builtin floating point to integer conversions do, rather than shifted away - which would round a negative value towards minus infinity. | |
| constexpr | operator uint64_t () const noexcept |
| operator uint64_t - converts to a uint64_t A negative value wraps modulo 2^64, the way a builtin signed to unsigned conversion does. | |
| constexpr | operator int32_t () const noexcept |
| operator int32_t - converts to a int32_t | |
| constexpr | operator uint32_t () const noexcept |
| operator uint32_t - converts to a uint32_t | |
| constexpr | operator float () const noexcept |
| operator float - converts to a float Not constexpr: the result is assembled through the Float union, and writing one member of a union and reading another is not allowed during constant evaluation. | |
| constexpr | operator double () const noexcept |
| operator double - converts to a double The whole value range is within reach of a double's exponent, so nothing overflows or goes denormal. Not constexpr: the result is assembled through the Double union, and writing one member of a union and reading another is not allowed during constant evaluation. | |
| constexpr | operator long double () const noexcept |
| operator long double - converts to a long double | |
| 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. | |
Arithmetic Operators | |
| template<typename T> | |
| constexpr fixed_point128 | operator>> (T shift) const noexcept |
| Performs right shift operation. | |
| template<typename T> | |
| constexpr fixed_point128 | operator<< (T shift) const noexcept |
| Performs left shift operation. Hinted rather than forced, see operator>> above. | |
| constexpr fixed_point128 & | operator+= (const fixed_point128 &rhs) noexcept |
| Add a value to this object. | |
| template<typename T> | |
| constexpr fixed_point128 & | operator+= (const T &rhs) noexcept |
| Add a value to this object. | |
| constexpr fixed_point128 & | operator-= (const fixed_point128 &rhs) noexcept |
| Subtract a value to this object. | |
| template<typename T> | |
| constexpr fixed_point128 & | operator-= (const T &rhs) noexcept |
| Subtract a value to this object. | |
| constexpr fixed_point128 & | operator*= (const fixed_point128 &rhs) noexcept |
| Multiplies a value to this object. | |
| constexpr fixed_point128 & | square () noexcept |
| Squares this object in place. | |
| template<typename T> | |
| constexpr fixed_point128 & | operator*= (T x) noexcept |
| Multiplies a value to this object. | |
| template<> | |
| constexpr fixed_point128 & | operator*= (uint64_t x) noexcept |
| Multiplies a 64 bit value to this object The product is taken modulo 2^128, which is the signed product of a two's complement value by an unsigned one: multiplying is repeated addition and addition already wraps correctly. | |
| fixed_point128 & | operator/= (const fixed_point128 &rhs) |
| Divide this object by x. The quotient is rounded to nearest, a tie going away from zero, whichever of the three paths below computes it. | |
| template<typename T> | |
| fixed_point128 & | operator/= (T x) |
| Divide this object by x. | |
| template<> | |
| fixed_point128 & | operator/= (double x) |
| Divide this object by x. | |
| template<> | |
| fixed_point128 & | operator/= (uint64_t x) |
| Divide this object by x. The quotient is rounded to nearest, a tie going away from zero: the same result as dividing by fixed_point128(x), which the integer divisor only makes cheaper. | |
| fixed_point128 & | operator%= (const fixed_point128 &rhs) |
| %= operator, the remainder of a truncating division: x - y * trunc(x / y). | |
| template<typename T> | |
| fixed_point128 & | operator%= (T rhs) |
| Performs modulo with a generic type by converting to fixed_point128. | |
| constexpr fixed_point128 & | operator>>= (int32_t shift) noexcept |
| Shift right this object. The shift is arithmetic: the sign bit is replicated, so the result is the value divided by 2^shift and rounded to nearest, a tie going away from zero - the rounding rule of the multiply and the divisions. | |
| constexpr fixed_point128 & | operator<<= (int32_t shift) noexcept |
| Shift left this object. A value shifted past the range of the type wraps silently, sign included. | |
| constexpr fixed_point128 & | operator&= (const fixed_point128 &rhs) noexcept |
| Bitwise AND= The operators below work on all 128 bits, the sign bit included. | |
| template<typename T> | |
| constexpr fixed_point128 & | operator&= (const T &rhs) |
| Bitwise AND=. | |
| constexpr fixed_point128 & | operator|= (const fixed_point128 &rhs) noexcept |
| Bitwise OR=. | |
| template<typename T> | |
| constexpr fixed_point128 & | operator|= (const T &rhs) |
| Bitwise OR=. | |
| constexpr fixed_point128 & | operator^= (const fixed_point128 &rhs) noexcept |
| Bitwise XOR=. | |
| template<typename T> | |
| constexpr fixed_point128 & | operator^= (const T &rhs) |
| Bitwise XOR=. | |
| constexpr fixed_point128 & | operator++ () noexcept |
| Prefix ++ operation (++a) | |
| constexpr fixed_point128 | operator++ (int32_t) noexcept |
| Postfix ++ operation (a++) | |
| constexpr fixed_point128 & | operator-- () noexcept |
| Prefix – operation (–a) | |
| constexpr fixed_point128 | operator-- (int32_t) noexcept |
| Postfix – operation (a–) | |
| constexpr | operator bool () const noexcept |
| Convert to bool. | |
| constexpr bool | operator! () const noexcept |
| Logical not (!). Opposite of operator bool. | |
| constexpr fixed_point128 | operator~ () const noexcept |
| Bitwise not (~). Flips all 128 bits, the sign included, which makes it -x - epsilon(). | |
| constexpr fixed_point128 | operator+ () const noexcept |
| Unary +. Returns a copy of the object. | |
| constexpr fixed_point128 | operator- () const noexcept |
| Unary -. Returns the two's complement of the object. The most negative value has no positive counterpart and is returned unchanged, the same silent wrap the builtin integer types perform. | |
Static Public Attributes | |
| static constexpr int32_t | F = 127 - I |
| Fraction bit count (127 - I). The remaining bit is the sign. | |
| static constexpr uint64_t | max_int_value = FP128_MAX_VALUE_64(I) |
| Largest representable positive integer, 2^I - 1. | |
Friends | |
| template<int32_t I2> | |
| class | fixed_point128 |
| class | fp128_gtest |
| template<int32_t J> | |
| std::istream & | operator>> (std::istream &is, fixed_point128< J > &value) |
Binary Math Operators (Friend) | |
| template<typename T> | |
| constexpr fixed_point128 | operator+ (fixed_point128 lhs, const T &rhs) noexcept |
| Adds 2 values and returns the result. | |
| template<typename T> | |
| constexpr fixed_point128 | operator- (fixed_point128 lhs, const T &rhs) noexcept |
| subtracts the right hand side operand to this object to and returns the result. | |
| template<typename T> | |
| constexpr fixed_point128 | operator* (fixed_point128 lhs, const T &rhs) noexcept |
| Multiplies the right hand side operand with this object to and returns the result. | |
| template<typename T> | |
| fixed_point128 | operator/ (fixed_point128 lhs, const T &rhs) |
| Divides this object by the right hand side operand and returns the result. | |
| template<typename T> | |
| fixed_point128 | operator% (fixed_point128 lhs, const T &rhs) |
| Calculates modulo. | |
Binary Bitwise Operators (Friend) | |
| template<typename T> | |
| constexpr fixed_point128 | operator& (fixed_point128 lhs, const T &rhs) |
| Performs bitwise AND (&) | |
| template<typename T> | |
| constexpr fixed_point128 | operator| (fixed_point128 lhs, const T &rhs) |
| Performs bitwise OR (|) | |
| template<typename T> | |
| constexpr fixed_point128 | operator^ (fixed_point128 lhs, const T &rhs) |
| Performs bitwise XOR (^) | |
Binary Operators With The Scalar On The Left Hand Side (Friend) | |
Overloads that accept a builtin arithmetic type as the left operand. Without these, an expression like (1 + x) is ambiguous: converting the literal to fixed_point128 and converting x to a builtin type are both one user defined conversion, so neither overload wins. Restricting the left operand to the arithmetic types keeps these from competing with the fixed_point128 on the left versions above, which would otherwise be an equally good match. The comparison operators already carry the same pair of overloads. The scalar is widened to fixed_point128 rather than the object being narrowed to a builtin type, so (1 - x) keeps the fraction of x instead of truncating it away. | |
| template<typename T> requires std::is_arithmetic_v<T> | |
| constexpr fixed_point128 | operator+ (const T &lhs, const fixed_point128 &rhs) noexcept |
| Adds a scalar and a fixed_point128, in that order. | |
| template<typename T> requires std::is_arithmetic_v<T> | |
| constexpr fixed_point128 | operator- (const T &lhs, const fixed_point128 &rhs) noexcept |
| Subtracts a fixed_point128 from a scalar. | |
| template<typename T> requires std::is_arithmetic_v<T> | |
| constexpr fixed_point128 | operator* (const T &lhs, const fixed_point128 &rhs) noexcept |
| Multiplies a scalar and a fixed_point128, in that order. | |
| template<typename T> requires std::is_arithmetic_v<T> | |
| fixed_point128 | operator/ (const T &lhs, const fixed_point128 &rhs) |
| Divides a scalar by a fixed_point128. | |
| template<typename T> requires std::is_arithmetic_v<T> | |
| fixed_point128 | operator% (const T &lhs, const fixed_point128 &rhs) |
| Performs modulo of a scalar by a fixed_point128. | |
| template<typename T> requires std::is_arithmetic_v<T> | |
| constexpr fixed_point128 | operator& (const T &lhs, const fixed_point128 &rhs) |
| Performs bitwise AND of a scalar and a fixed_point128. | |
| template<typename T> requires std::is_arithmetic_v<T> | |
| constexpr fixed_point128 | operator| (const T &lhs, const fixed_point128 &rhs) |
| Performs bitwise OR of a scalar and a fixed_point128. | |
| template<typename T> requires std::is_arithmetic_v<T> | |
| constexpr fixed_point128 | operator^ (const T &lhs, const fixed_point128 &rhs) |
| Performs bitwise XOR of a scalar and a fixed_point128. | |
| template<typename T> requires std::is_arithmetic_v<T> | |
| constexpr fixed_point128 | operator<< (const T &lhs, const fixed_point128 &rhs) noexcept |
| Shifts a scalar left by a fixed_point128 shift count. | |
| template<typename T> requires std::is_arithmetic_v<T> | |
| constexpr fixed_point128 | operator>> (const T &lhs, const fixed_point128 &rhs) noexcept |
| Shifts a scalar right by a fixed_point128 shift count. The left operand is widened to fixed_point128 first, see operator<< above. | |
Comparison Operators | |
| constexpr bool | operator== (const fixed_point128 &lhs, const fixed_point128 &rhs) noexcept |
| Compare logical/bitwise equal. | |
| template<typename T> | |
| constexpr bool | operator== (const fixed_point128 &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 fixed_point128 &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 fixed_point128 &lhs, const fixed_point128 &rhs) noexcept |
| Return true when objects are not equal. Can be used as logical XOR. | |
| template<typename T> | |
| constexpr bool | operator!= (const fixed_point128 &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 fixed_point128 &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 fixed_point128 &lhs, const fixed_point128 &rhs) noexcept |
| Return true if this object is small than the rhs. | |
| template<typename T> | |
| constexpr bool | operator< (const fixed_point128 &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 fixed_point128 &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 fixed_point128 &lhs, const fixed_point128 &rhs) noexcept |
| Return true this object is small or equal than the rhs. | |
| template<typename T> | |
| constexpr bool | operator<= (const fixed_point128 &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 fixed_point128 &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 fixed_point128 &lhs, const fixed_point128 &rhs) noexcept |
| Return true this object is larger than the rhs. | |
| template<typename T> | |
| constexpr bool | operator> (const fixed_point128 &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 fixed_point128 &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 fixed_point128 &lhs, const fixed_point128 &rhs) noexcept |
| Return true this object is larger or equal than the rhs. | |
| template<typename T> | |
| constexpr bool | operator>= (const fixed_point128 &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 fixed_point128 &rhs) noexcept |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Friend Math Functions | |
CRT-style math functions implemented as friend functions. | |
| constexpr fixed_point128 | fabs (const fixed_point128 &x) |
| Returns the absolute value. | |
| constexpr fixed_point128 | floor (const fixed_point128 &x) |
| Performs the floor() function, similar to libc's floor(), rounds down towards -infinity. | |
| constexpr fixed_point128 | ceil (const fixed_point128 &x) |
| Performs the ceil() function, similar to libc's ceil(), rounds up towards infinity. | |
| constexpr fixed_point128 | trunc (const fixed_point128 &x) |
| Rounds towards zero. | |
| constexpr fixed_point128 | round (const fixed_point128 &x) |
| Rounds towards the nearest integer. The halfway value (0.5) is rounded away from zero. | |
| constexpr int32_t | ilogb (const fixed_point128 &x) |
| Retrieves an integer that represents the base-2 exponent of the specified value. floor(log2(|x|)), as the C function: the sign of x makes no difference. | |
| constexpr fixed_point128 | copysign (const fixed_point128 &x, const fixed_point128 &y) |
| returns the value of x with the sign of y. | |
| fixed_point128 | fmod (const fixed_point128 &x, const fixed_point128 &y) |
| Performs the fmod() function, similar to libc's fmod(): x - y * trunc(x / y). Exact, and the result keeps the sign of x. See operator%=(). | |
| constexpr fixed_point128 | modf (const fixed_point128 &x, fixed_point128 *iptr) |
| Split into integer and fraction parts. Both results carry the sign of the input variable. | |
| constexpr fixed_point128 | fdim (const fixed_point128 &x, const fixed_point128 &y) |
| Determines the positive difference between the first and second values. | |
| constexpr fixed_point128 | fmin (const fixed_point128 &x, const fixed_point128 &y) |
| Returns the minimum between x and y. | |
| constexpr fixed_point128 | fmax (const fixed_point128 &x, const fixed_point128 &y) |
| Returns the maximum between x and y. | |
| fixed_point128 | hypot (const fixed_point128 &x, const fixed_point128 &y) |
| Calculates the hypotenuse. i.e. sqrt(x^2 + y^2) | |
| constexpr fixed_point128 | sqr (fixed_point128 x) noexcept |
| Calculates the square of a value. i.e. x^2. | |
| constexpr uint64_t | lzcnt128 (const fixed_point128 &x) |
| Calculates the left zero count of value x, ignoring the sign. Counted on the magnitude, so a negative value gives the same answer as its opposite rather than the zero its two's complement bits would produce. | |
| fixed_point128 | sqrt (const fixed_point128 &x, uint32_t iterations=3) |
| Calculates the square root, correctly rounded. | |
| void | fact_reciprocal (int x, fixed_point128 &res) |
| Factorial reciprocal (inverse). Calculates 1 / x! Maximum value of x that may produce non zero values is 34. This value depends on the amount of fraction bits. The table is parsed from decimal strings, so it carries the accuracy of the string constructor: within 0.5 + 23 / 2^(I-1) ulp of the exact 1 / x!, measured 17.5 ulp at I = 1 and 0.5 from I = 16 up. | |
| fixed_point128 | reciprocal (const fixed_point128 &x) |
| Calculates the reciprocal of a value. y = 1 / x. | |
| void | _sincos_cordic (fixed_point128 x, fixed_point128 &sin_x, fixed_point128 &cos_x, bool apply_scale_factor) noexcept |
| Calculate Sine and Cosine using CORDIC using a limited range of [-pi/2, pi/2] 64 iterations, one per entry of the arctangent table, which give an absolute accuracy of about 2^-63: measured within 1.1e-19 of mpmath for |x| < 1. The table used to skip arctan(2^-62), which held the error near 1.8e-19. Not used by tan(), which divides sin() by cos(). | |
| fixed_point128 | sin1 (fixed_point128 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! The series runs in a wider fraction than this instantiation has, see TrigSeries(). | |
| fixed_point128 | cos1 (const fixed_point128 &x) noexcept |
| Calculate the cosine function over a limited range [-0.5pi, 0.5pi] Using the Maclaurin series expansion, the formula is: x^2 x^4 x^6 cos(x) = 1 - — + — - — + ... 2! 4! 6! Evaluated directly rather than as sin1(pi/2 - x), which carried the rounding error of pi/2 into every result; cos1(0) is now exactly one. See TrigSeries(). | |
| fixed_point128 | sin (fixed_point128 x) |
| Calculate the Sine function Ultimately uses sin1() or cos1() with a reduced range of [-pi/4, pi/4]. | |
| fixed_point128 | asin (fixed_point128 x) |
| Calculate the inverse sine function Newton's method on sin() for |x| up to one half, see AsinNewton(). Beyond that the identity asin(x) = pi/2 - 2 asin(sqrt((1 - x) / 2)) keeps the iteration away from pi/2, where the derivative it divides by vanishes and the refinement stalled at double precision: asin(1) was 4e16 ulp off at fixed_point128<16>. The square root is correctly rounded, so the identity costs a few ulp at most. | |
| fixed_point128 | cos (fixed_point128 x) |
| Calculate the cosine function Ultimately uses sin1() or cos1() with a reduced range of [-pi/4, pi/4]. cos(0) is exactly one. | |
| fixed_point128 | acos (fixed_point128 x) |
| Calculate the inverse cosine function pi/2 - asin(x) for |x| up to one half. Beyond that acos(x) = 2 asin(sqrt((1 - x) / 2)) for a positive x and pi - 2 asin(sqrt((1 + x) / 2)) for a negative one, which keep Newton's method away from the ends of the domain: acos(-1) was 8e16 ulp off at fixed_point128<16>. | |
| fixed_point128 | tan (fixed_point128 x) |
| Calculate the tangent function tan(x) = sin(x)/cos(x) | |
| fixed_point128 | atan (fixed_point128 x) |
| Calculate the inverse tangent function Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 2.2 ulp. | |
| fixed_point128 | atan2 (fixed_point128 y, fixed_point128 x) |
| Calculate the inverse tangent function of the ratio y / x Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 3.3 ulp. | |
| fixed_point128 | sinh (const fixed_point128 &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 Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 10 * max(1, |sinh(x)|) ulp at I = 4 and 3 * max(1, |sinh(x)|) ulp from I = 16 up. e^x itself has to fit the range, so a result between 2^(I-1) and 2^I overflows. | |
| fixed_point128 | asinh (const fixed_point128 &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. The root is exact before it is rounded (RootOfSquareAndOne()) and the sum is kept from overflowing (LogOfSum()), so every argument works, lowest() included. Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 over the whole range: within 2.8 ulp. | |
| fixed_point128 | cosh (const fixed_point128 &x) |
| Calculate the hyperbolic cosine function e^x + e^(-x) cosh(x) = ---------— 2 Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 10 * max(1, cosh(x)) ulp at I = 4 and 3 * max(1, cosh(x)) ulp from I = 16 up. e^|x| itself has to fit the range, see sinh(). | |
| fixed_point128 | acosh (const fixed_point128 &x) |
| Calculates the inverse hyperbolic cosine For x >= 1: acosh(x) = log(x + sqrt(x^2 - 1)) For x < 1, the function return zero Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 over the whole range: within 2.9 ulp. It was out by up to 5e8 ulp just above one, where x^2 - 1 cancels. | |
| fixed_point128 | tanh (const fixed_point128 &x) |
| Calculates the hyperbolic tangent e^x - e^(-x) 1 - e^(-2|x|) tanh(x) = ---------— = ------------—, with the sign of x e^x + e^(-x) 1 + e^(-2|x|) The second form is the one evaluated, for every argument. Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 4.2 ulp. | |
| fixed_point128 | atanh (const fixed_point128 &x) |
| Calculates the inverse hyperbolic tangent 1 + x atanh(x) = 0.5 * log( --—) = 0.5 * (log(1 + x) - log(1 - x)) 1 - x The second form is the one evaluated. Both of its logarithms take an argument in (0, 2), inside the range of every instantiation, while the quotient of the first form leaves the range as x approaches one - beyond 0.88 at fixed_point128<4>, within 2^-15 of one at fixed_point128<16> - and the wrapped value made log() throw out of this noexcept function, terminating the process. Accuracy, measured against mpmath at I = 4, 16, 32, 62 and 63: within 1.4 ulp. Below I = 4 the same holds where log(1 - x) fits the range, which log() needs for its log2 (see log()): for |x| up to 0.75 at I = 1 and 0.9375 at I = 2. | |
| fixed_point128 | exp (const fixed_point128 &x) |
| 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! | |
| fixed_point128 | expm1 (const fixed_point128 &x) |
| Calculates the exponent of x and reduces 1 from the result: (e^x) - 1 Evaluated as exp(x) - 1, which in a fixed point type loses nothing to cancellation: the absolute error is that of exp(), within 9.3 * max(1, |e^x - 1|) ulp measured at I = 4 and 6.2 * max(1, e^x) ulp from I = 16 up. | |
| fixed_point128 | exp2 (const fixed_point128 &x) |
| Computes 2 to the power of x exp(x * ln(2)), the constant applied with 128 fraction bits. Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 5.5 * max(1, 2^x) ulp. | |
| fixed_point128 | pow (const fixed_point128 &x, const fixed_point128 &y) |
| Computes x to the power of y exp(y * log(x)). Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 7.3 * max(1, x^y) ulp at I = 4 and 4.4 * max(1, x^y) ulp from I = 16 up. Exact powers are not exact: pow(2, 3) is 8 - 15 ulp at I = 16. y * log(x) has to fit the range. | |
| constexpr fixed_point128 | log2 (fixed_point128 x) |
| Calculates the Log base 2 of x: y = log2(x) Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 2 ulp at I = 1, 1.7 ulp at I = 2 and 1.1 ulp from I = 4 up. The compile time evaluation takes a different, bitwise path that truncates instead: it can be one ulp below the runtime result. A result outside the range wraps, which a narrow instantiation meets for small arguments: log2(x) needs x >= 2^(-2^I). | |
| fixed_point128 | log (fixed_point128 x) |
| Calculates the natural Log (base e) of x: log(x) log2(x) * ln(2), the constant applied with 128 fraction bits by MulByFraction128() - a constant held to this instantiation's F bits, multiplied by a log2 of up to 63, would cost tens of ulp. Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 1.9 ulp. log2(x) has to fit the range as well, so a narrow instantiation cannot take the log of an argument below 2^(-2^I) even when its log would fit: at I = 1 that is x below 0.25. | |
| fixed_point128 | log1p (fixed_point128 x) |
| Calculates the natural Log (base e) of 1 + x: log(1 + x) Not noexcept: it forwards to log(), which rejects a non positive argument. Marking it noexcept would turn that domain_error into a call to std::terminate. 1 + x is exact in a fixed point type, so the error is that of log(): within 1.2 ulp measured, with log()'s limit on small arguments at I < 7. | |
| fixed_point128 | log10 (fixed_point128 x) |
| Calculates Log base 10 of x: log10(x) log2(x) * log10(2), the constant applied with 128 fraction bits, see log(). Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 1 ulp, with log()'s limit on small arguments at I < 7. | |
| constexpr fixed_point128 | logb (fixed_point128 x) |
| Calculates Log base 2 of x as an integer ignoring the sign of x. floor(log2(fabs(x))), as the C function: logb(-8) is 3. A narrow instantiation cannot hold the exponent of its smallest values - logb(epsilon()) is -126 for fixed_point128<1> - and the result then wraps like any other overflow. | |
Query and Utility Functions | |
| constexpr bool | is_int () const noexcept |
| Returns true if the value is an int (fraction is zero) | |
| constexpr bool | is_positive () const noexcept |
| Returns true if the value is positive (including zero) | |
| constexpr bool | is_negative () const noexcept |
| Returns true if the value negative (smaller than zero) | |
| constexpr bool | is_zero () const noexcept |
| Returns true if the value is zero. | |
| constexpr int32_t | get_bit (uint32_t bit) const noexcept |
| get a specific bit within the 128 fixed point data | |
| 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. Reads the magnitude, so the sign of the value makes no difference. | |
| static const fixed_point128 & | pi () noexcept |
| Returns an instance of fixed_point128 with the value of pi Needs I to be 2 or more. | |
| static const fixed_point128 & | pi2 () noexcept |
| Returns an instance of fixed_point128 with the value of pi * 2 Needs I to be 3 or more. | |
| static const fixed_point128 & | half_pi () noexcept |
| Returns an instance of fixed_point128 with the value of pi / 2. | |
| static const fixed_point128 & | golden_ratio () noexcept |
| Returns an instance of fixed_point128 with the value of the golden ratio. | |
| static const fixed_point128 & | e () noexcept |
| Returns an instance of fixed_point128 with the value of e Needs I to be 2 or more. | |
| static const fixed_point128 & | sqrt_2 () noexcept |
| Returns an instance of fixed_point128 with the value of sqrt(2) | |
| static constexpr fixed_point128 | one () noexcept |
| Return an instance of fixed_point128 with the value of 1 These three exact constants are returned by value rather than by reference like the transcendental ones above: they are representable in every instantiation without a string conversion, so a constexpr function can build them on the spot and callers get a compile time constant instead of a lazily initialized static. | |
| static constexpr fixed_point128 | half () noexcept |
| Return an instance of fixed_point128 with the value of 0.5 Shifting one() right is exact for any I. Note that 0.5 lands in the low QWORD when I is 63, which rules out spelling it as a constant of the upper QWORD alone. | |
| static constexpr fixed_point128 | epsilon () noexcept |
| Return an instance of fixed_point128 with the smallest positive value possible. | |
Google test class (friend).
128 bit fixed point class template.
This template provides a floating point-like type that performs various math operations quickly compared to traditional high precision libraries. The only template parameter I is the bit count of the integer part, not counting the sign. The sign takes one bit and the fraction takes the remaining 127 - I.
I is limited to the range [1,63] in order to simplify the implementation and increase performance.
This restriction is enforced at compile time. All of fixed_point128's methods are inline for maximum performance.
Representation:
The object is exactly 128 bits wide and holds nothing but the value. Those bits are a two's complement integer, held as the QWORD pair (high:low) with the sign in the MSB of high, and the value they stand for is that integer divided by 2^F:
The representable range is therefore [-2^I, 2^I - 2^-F], which is the asymmetric range of every two's complement type: the most negative value has no positive counterpart, so negating it (and fabs of it) wraps back to itself.
Minimum integer bits:
Some of the constants and functions cannot work in the narrowest instantiations, and each one says so with a static_assert in its body rather than by overflowing quietly or failing to link. The bound is the smallest I that works, not a safe margin:
Everything else works for every I, including half_pi(), sqrt_2() and golden_ratio(), which are all below two. A function whose result leaves the range - exp() of a large argument, log() of a tiny one - is a matter of the argument rather than of the type, and overflows silently like any other operation.
Implementation notes:
Compile time evaluation:
Everything that stays within integer arithmetic is constexpr:
The bit counting and extended arithmetic intrinsics these rest on 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. A runtime call still reaches the bare intrinsic and generates the same code it did before.
The rest cannot be constexpr, for one of two reasons:
Definition at line 302 of file fixed_point128.h.
| typedef fixed_point128<I> fp128::fixed_point128< I >::type |
Self type alias.
Definition at line 582 of file fixed_point128.h.
| typedef fixed_point128<I>* fp128::fixed_point128< I >::ptr_type |
Pointer type alias.
Definition at line 583 of file fixed_point128.h.
| typedef fixed_point128<I>& fp128::fixed_point128< I >::ref_type |
Reference type alias.
Definition at line 584 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Default constructor, creates an instance with a value of zero.
Definition at line 592 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Copy constructor.
| rhs | Object to copy from |
Definition at line 597 of file fixed_point128.h.
|
inlineconstexprnoexcept |
cross-template Copy constructor, can be used between two different fixed_point128 templates A value too large for the destination wraps silently, as everywhere else in this class. Fraction bits the destination cannot hold are rounded to nearest, a tie going away from zero.
| rhs | fixed_point128 instance with from a different template instance. |
Definition at line 604 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Move constructor Doesn't modify the right hand side object. Acts like a copy constructor.
| rhs | Object to copy from |
Definition at line 633 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Constructor from the double type Underflow goes to zero. Overflow, NaN and +-INF saturate to the extreme value carrying the sign of the input: max() for a positive one and lowest() for a negative one. Not constexpr: the exponent and mantissa are read through the Double union, and reading the inactive member of a union is not allowed during constant evaluation.
| x | Input value |
Definition at line 642 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Constructor from uint64_t type A value of 2^I or above overflows into the sign and wraps silently.
| x | Input value |
Definition at line 709 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Constructor from int64_t type The shift is done in the unsigned domain, where it wraps rather than overflowing, and a negative value carries its sign bits along with it: scaling a two's complement value by a power of two is the same left shift its magnitude needs.
| x | Input value |
Definition at line 721 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Constructor from uint32_t type.
| x | Input value |
Definition at line 730 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Constructor from int32_t type.
| x | Input value |
Definition at line 739 of file fixed_point128.h.
|
inlinenoexcept |
Constructor from const char* (C string).
Reads optional leading white space, an optional sign, decimal digits and an optional point followed by more digits, and stops at the first character that is not part of that. The value is the grid value nearest the decimal one, a tie going away from zero - correctly rounded for any number of digits and any I, which is what lets every value survive the trip through its own text form.
The digits after the point are read as one exact integer and scaled by 2^F / 10^digits in big integer arithmetic, see ParseDecimal(). They used to be summed as a series of powers of ten held to 126 bits each, which was 22.8 ulp off at I = 1 and 3 ulp off at I = 4.
Much slower than the other constructors. A value too large for the type wraps silently, modulo 2^(I+1) in its integer part, which unlike the saturation the double constructor performs can land on either sign; the stream extractor reports it instead.
| x | Input string |
Definition at line 763 of file fixed_point128.h.
|
inlinenoexcept |
Constructor from std::string. Accurate to 37 digits after the decimal point. Allows creating very high precision values. Much slower than the rhs constructors.
| x | Input string |
Definition at line 783 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Constructor from the two QWORDs of the raw value, useful for creating very small constants. The pair is read as a 128 bit two's complement integer scaled by 2^-F, so a negative value is spelled with the MSB of h set rather than with a separate sign.
| l | Low QWORD |
| h | High QWORD, sign included |
Definition at line 795 of file fixed_point128.h.
|
constexprdefaultnoexcept |
Destructor.
|
inlineconstexprnoexcept |
Reads the raw representation: the two QWORDs of the 128 bit two's complement value.
| l | Receives the low QWORD |
| h | Receives the high QWORD, sign included |
Definition at line 575 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Assignment operator.
| rhs | Object to copy from |
Definition at line 806 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Move assignment operator.
| rhs | Object to copy from |
Definition at line 817 of file fixed_point128.h.
|
inlineconstexprnoexcept |
cross-template assignment operator, can be used between two different fixed_point128 templates Behaves as the cross-template constructor: a value too large for this instantiation wraps, and fraction bits it cannot hold are rounded to nearest, a tie going away from zero.
| rhs | fixed_point128 instance with from a different template instance. |
Definition at line 830 of file fixed_point128.h.
|
inlinenodiscardconstexprnoexcept |
operator int64_t - converts to a int64_t The fraction is truncated towards zero, as the builtin floating point to integer conversions do, rather than shifted away - which would round a negative value towards minus infinity.
Definition at line 867 of file fixed_point128.h.
|
inlinenodiscardconstexprnoexcept |
operator uint64_t - converts to a uint64_t A negative value wraps modulo 2^64, the way a builtin signed to unsigned conversion does.
Definition at line 881 of file fixed_point128.h.
|
inlinenodiscardconstexprnoexcept |
operator int32_t - converts to a int32_t
Definition at line 886 of file fixed_point128.h.
|
inlinenodiscardconstexprnoexcept |
operator uint32_t - converts to a uint32_t
Definition at line 891 of file fixed_point128.h.
|
inlinenodiscardconstexprnoexcept |
operator float - converts to a float Not constexpr: the result is assembled through the Float union, and writing one member of a union and reading another is not allowed during constant evaluation.
Definition at line 898 of file fixed_point128.h.
|
inlinenodiscardconstexprnoexcept |
operator double - converts to a double The whole value range is within reach of a double's exponent, so nothing overflows or goes denormal. Not constexpr: the result is assembled through the Double union, and writing one member of a union and reading another is not allowed during constant evaluation.
Definition at line 933 of file fixed_point128.h.
|
inlinenodiscardconstexprnoexcept |
operator long double - converts to a long double
Definition at line 961 of file fixed_point128.h.
|
inlinenodiscardnoexcept |
Converts to a std::string (slow) string holds all meaningful fraction bits.
Definition at line 966 of file fixed_point128.h.
|
inlineexplicitnodiscardnoexcept |
Converts to a C string (slow) string holds all meaningful fraction bits.
Definition at line 971 of file fixed_point128.h.
|
inlinenodiscardconstexprnoexcept |
Performs right shift operation.
Hinted rather than forced, unlike the other one line forwarders (see FP128_FORCE_INLINE). operator>>= is itself forced, so forcing this one too would expand the whole shift, its rounding included, at every use of the by value form. The equivalent pair in float128 measurably hurt a loop that shifts alongside other arithmetic; this one is left hinted for the same reason. The callee being forced means the shift is inlined either way once the compiler decides to inline this wrapper.
| shift | bits to shift |
Definition at line 1070 of file fixed_point128.h.
|
inlinenodiscardconstexprnoexcept |
Performs left shift operation. Hinted rather than forced, see operator>> above.
| shift | bits to shift |
Definition at line 1081 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Add a value to this object.
| rhs | Right hand side operand |
Definition at line 1091 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Add a value to this object.
| rhs | Right hand side operand |
Definition at line 1104 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Subtract a value to this object.
| rhs | Right hand side operand |
Definition at line 1110 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Subtract a value to this object.
| rhs | Right hand side operand |
Definition at line 1123 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Multiplies a value to this object.
| rhs | Right hand side operand |
Definition at line 1129 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Squares this object in place.
Cheaper than operator*=(*this): a square is symmetric, so the two cross products low*high and high*low are the same value and only one 64x64->128 bit multiply is needed instead of two. The sign is also known in advance - a magnitude times itself is the answer as it stands - which removes the sign combination and the negation.
The 256 bit intermediate product is accumulated exactly as in operator*=, so the result is bit identical to (*this) * (*this), including rounding.
Definition at line 1213 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Multiplies a value to this object.
| x | Right hand side operand |
Definition at line 1267 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Multiplies a 64 bit value to this object The product is taken modulo 2^128, which is the signed product of a two's complement value by an unsigned one: multiplying is repeated addition and addition already wraps correctly.
| x | Right hand side operand |
Definition at line 1300 of file fixed_point128.h.
|
inline |
Divide this object by x. The quotient is rounded to nearest, a tie going away from zero, whichever of the three paths below computes it.
| rhs | Right hand side operator (denominator) |
| std::logic_error | when rhs is zero - zero divided by zero included - leaving this object in an unspecified state: the magnitude of what it held, the sign not yet put back. |
Definition at line 1318 of file fixed_point128.h.
|
inline |
Divide this object by x.
| x | Denominator. |
Definition at line 1388 of file fixed_point128.h.
|
inline |
Divide this object by x.
| x | Denominator. |
Definition at line 1418 of file fixed_point128.h.
|
inline |
Divide this object by x. The quotient is rounded to nearest, a tie going away from zero: the same result as dividing by fixed_point128(x), which the integer divisor only makes cheaper.
| x | Denominator. |
| std::logic_error | when x is zero. |
Definition at line 1444 of file fixed_point128.h.
|
inline |
%= operator, the remainder of a truncating division: x - y * trunc(x / y).
The result is exact and keeps the sign of the numerator, as fmod() does. Two values on the same grid of 2^-F are integers scaled by the same power of two, so their remainder is the remainder of the raw 128 bit integers, scaled the same way: no quotient is formed, so it can neither overflow nor be rounded onto the wrong integer.
| rhs | Modulo operand. |
| std::logic_error | when rhs is zero, zero modulo zero included. |
Definition at line 1480 of file fixed_point128.h.
|
inline |
Performs modulo with a generic type by converting to fixed_point128.
| T | Right hand side type |
| rhs | Divisor |
Definition at line 1516 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Shift right this object. The shift is arithmetic: the sign bit is replicated, so the result is the value divided by 2^shift and rounded to nearest, a tie going away from zero - the rounding rule of the multiply and the divisions.
That rule makes +-epsilon() a fixed point of a shift by one: epsilon() >> 1 is exactly half an epsilon, a tie, and rounds back up to epsilon(). A loop that halves a value until it reaches zero has to bound its iterations or test for epsilon() instead.
| shift | Bits to shift. A negative count causes undefined behavior; 128 or more leaves zero, apart from lowest() >> 128, which is the tie -epsilon() / 2 and so -epsilon(). |
Definition at line 1530 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Shift left this object. A value shifted past the range of the type wraps silently, sign included.
| shift | Bits to shift. Negative or very high values cause undefined behavior. |
Definition at line 1541 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Bitwise AND= The operators below work on all 128 bits, the sign bit included.
| rhs | AND mask. |
Definition at line 1552 of file fixed_point128.h.
|
inlineconstexpr |
Bitwise AND=.
| rhs | Right hand side operand |
Definition at line 1563 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Bitwise OR=.
| rhs | OR mask. |
Definition at line 1569 of file fixed_point128.h.
|
inlineconstexpr |
Bitwise OR=.
| rhs | Right hand side operand |
Definition at line 1580 of file fixed_point128.h.
|
inlineconstexprnoexcept |
Bitwise XOR=.
| rhs | XOR mask. |
Definition at line 1586 of file fixed_point128.h.
|
inlineconstexpr |
Bitwise XOR=.
| rhs | Right hand side operand |
Definition at line 1597 of file fixed_point128.h.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlinenodiscardconstexprnoexcept |
Convert to bool.
Definition at line 1643 of file fixed_point128.h.
|
inlinenodiscardconstexprnoexcept |
Logical not (!). Opposite of operator bool.
Definition at line 1647 of file fixed_point128.h.
|
inlinenodiscardconstexprnoexcept |
Bitwise not (~). Flips all 128 bits, the sign included, which makes it -x - epsilon().
Definition at line 1651 of file fixed_point128.h.
|
inlinenodiscardconstexprnoexcept |
Unary +. Returns a copy of the object.
Definition at line 1661 of file fixed_point128.h.
|
inlinenodiscardconstexprnoexcept |
Unary -. Returns the two's complement of the object. The most negative value has no positive counterpart and is returned unchanged, the same silent wrap the builtin integer types perform.
Definition at line 1671 of file fixed_point128.h.
|
inlinenodiscardconstexprnoexcept |
Returns true if the value is an int (fraction is zero)
Definition at line 1687 of file fixed_point128.h.
|
inlinenodiscardconstexprnoexcept |
Returns true if the value is positive (including zero)
Definition at line 1700 of file fixed_point128.h.
|
inlinenodiscardconstexprnoexcept |
Returns true if the value negative (smaller than zero)
Definition at line 1705 of file fixed_point128.h.
|
inlinenodiscardconstexprnoexcept |
Returns true if the value is zero.
Definition at line 1710 of file fixed_point128.h.
|
inlinenodiscardconstexprnoexcept |
get a specific bit within the 128 fixed point data
| bit | bit to get [0,127] |
Definition at line 1716 of file fixed_point128.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. Reads the magnitude, so the sign of the value makes no difference.
Definition at line 1729 of file fixed_point128.h.
|
inlinestaticnodiscardnoexcept |
Returns an instance of fixed_point128 with the value of pi Needs I to be 2 or more.
Definition at line 1739 of file fixed_point128.h.
|
inlinestaticnodiscardnoexcept |
Returns an instance of fixed_point128 with the value of pi * 2 Needs I to be 3 or more.
Definition at line 1750 of file fixed_point128.h.
|
inlinestaticnodiscardnoexcept |
Returns an instance of fixed_point128 with the value of pi / 2.
Definition at line 1760 of file fixed_point128.h.
|
inlinestaticnodiscardnoexcept |
Returns an instance of fixed_point128 with the value of the golden ratio.
Definition at line 1769 of file fixed_point128.h.
|
inlinestaticnodiscardnoexcept |
Returns an instance of fixed_point128 with the value of e Needs I to be 2 or more.
Definition at line 1779 of file fixed_point128.h.
|
inlinestaticnodiscardnoexcept |
Returns an instance of fixed_point128 with the value of sqrt(2)
Definition at line 1789 of file fixed_point128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Return an instance of fixed_point128 with the value of 1 These three exact constants are returned by value rather than by reference like the transcendental ones above: they are representable in every instantiation without a string conversion, so a constexpr function can build them on the spot and callers get a compile time constant instead of a lazily initialized static.
Definition at line 1802 of file fixed_point128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Return an instance of fixed_point128 with the value of 0.5 Shifting one() right is exact for any I. Note that 0.5 lands in the low QWORD when I is 63, which rules out spelling it as a constant of the upper QWORD alone.
Definition at line 1809 of file fixed_point128.h.
|
inlinestaticnodiscardconstexprnoexcept |
Return an instance of fixed_point128 with the smallest positive value possible.
Definition at line 1814 of file fixed_point128.h.
Definition at line 309 of file fixed_point128.h.
|
friend |
Definition at line 310 of file fixed_point128.h.
|
friend |
|
friend |
Adds 2 values and returns the result.
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 2383 of file fixed_point128.h.
|
friend |
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 2395 of file fixed_point128.h.
|
friend |
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 2407 of file fixed_point128.h.
|
friend |
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 2418 of file fixed_point128.h.
|
friend |
Calculates modulo.
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 2429 of file fixed_point128.h.
|
friend |
Performs bitwise AND (&)
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 2446 of file fixed_point128.h.
|
friend |
Performs bitwise OR (|)
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 2457 of file fixed_point128.h.
|
friend |
Performs bitwise XOR (^)
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 2468 of file fixed_point128.h.
|
friend |
Adds a scalar and a fixed_point128, in that order.
| lhs | Left operand |
| rhs | Right operand |
Definition at line 2492 of file fixed_point128.h.
|
friend |
Subtracts a fixed_point128 from a scalar.
| lhs | Left operand |
| rhs | Right operand |
Definition at line 2499 of file fixed_point128.h.
|
friend |
Multiplies a scalar and a fixed_point128, in that order.
| lhs | Left operand |
| rhs | Right operand |
Definition at line 2506 of file fixed_point128.h.
|
friend |
Divides a scalar by a fixed_point128.
| lhs | Left operand |
| rhs | Right operand |
Definition at line 2513 of file fixed_point128.h.
|
friend |
Performs modulo of a scalar by a fixed_point128.
| lhs | Left operand |
| rhs | Right operand |
Definition at line 2520 of file fixed_point128.h.
|
friend |
Performs bitwise AND of a scalar and a fixed_point128.
| lhs | Left operand |
| rhs | Right operand |
Definition at line 2527 of file fixed_point128.h.
|
friend |
Performs bitwise OR of a scalar and a fixed_point128.
| lhs | Left operand |
| rhs | Right operand |
Definition at line 2534 of file fixed_point128.h.
|
friend |
Performs bitwise XOR of a scalar and a fixed_point128.
| lhs | Left operand |
| rhs | Right operand |
Definition at line 2541 of file fixed_point128.h.
|
friend |
Shifts a scalar left by a fixed_point128 shift count.
The left operand is widened to fixed_point128 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 fixed_point128 on the left overload applies. That conversion is a shift, so the fraction of rhs is truncated toward zero rather than rounded.
| lhs | Left operand, the value being shifted |
| rhs | Right operand, the shift count |
Definition at line 2561 of file fixed_point128.h.
|
friend |
Shifts a scalar right by a fixed_point128 shift count. The left operand is widened to fixed_point128 first, see operator<< above.
| lhs | Left operand, the value being shifted |
| rhs | Right operand, the shift count |
Definition at line 2574 of file fixed_point128.h.
|
friend |
Compare logical/bitwise equal.
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 2590 of file fixed_point128.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 2595 of file fixed_point128.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 2600 of file fixed_point128.h.
|
friend |
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 2610 of file fixed_point128.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 2615 of file fixed_point128.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 2620 of file fixed_point128.h.
|
friend |
Return true if this object is small than the rhs.
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 2630 of file fixed_point128.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 2640 of file fixed_point128.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 2645 of file fixed_point128.h.
|
friend |
Return true this object is small or equal than the rhs.
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 2655 of file fixed_point128.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 2657 of file fixed_point128.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 2662 of file fixed_point128.h.
|
friend |
Return true this object is larger than the rhs.
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 2672 of file fixed_point128.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 2681 of file fixed_point128.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 2686 of file fixed_point128.h.
|
friend |
Return true this object is larger or equal than the rhs.
| lhs | left hand side operand |
| rhs | Right hand side operand |
Definition at line 2696 of file fixed_point128.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 2698 of file fixed_point128.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 2703 of file fixed_point128.h.
|
friend |
Returns the absolute value.
| x | Input value |
Definition at line 2720 of file fixed_point128.h.
|
friend |
Performs the floor() function, similar to libc's floor(), rounds down towards -infinity.
| x | Input value |
Definition at line 2733 of file fixed_point128.h.
|
friend |
Performs the ceil() function, similar to libc's ceil(), rounds up towards infinity.
| x | Input value |
Definition at line 2745 of file fixed_point128.h.
|
friend |
Rounds towards zero.
| x | Value to truncate |
Definition at line 2758 of file fixed_point128.h.
|
friend |
Rounds towards the nearest integer. The halfway value (0.5) is rounded away from zero.
| x | Value to round |
Definition at line 2769 of file fixed_point128.h.
|
friend |
Retrieves an integer that represents the base-2 exponent of the specified value. floor(log2(|x|)), as the C function: the sign of x makes no difference.
| x | The specified value. |
Definition at line 2782 of file fixed_point128.h.
|
friend |
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 2792 of file fixed_point128.h.
|
friend |
Performs the fmod() function, similar to libc's fmod(): x - y * trunc(x / y). Exact, and the result keeps the sign of x. See operator%=().
| x | Numerator |
| y | Denominator |
| std::logic_error | when y is zero. This type has no NaN to return instead. |
Definition at line 2805 of file fixed_point128.h.
|
friend |
Split into integer and fraction parts. Both results carry the sign of the input variable.
| x | Input value |
| iptr | Pointer to fixed_point128 holding the integer part of x. |
Definition at line 2813 of file fixed_point128.h.
|
friend |
Determines the positive difference between the first and second values.
| x | First value |
| y | Second value |
Definition at line 2829 of file fixed_point128.h.
|
friend |
Returns the minimum between x and y.
| x | First value |
| y | Second value |
Definition at line 2839 of file fixed_point128.h.
|
friend |
Returns the maximum between x and y.
| x | First value |
| y | Second value |
Definition at line 2846 of file fixed_point128.h.
|
friend |
Calculates the hypotenuse. i.e. sqrt(x^2 + y^2)
Correctly rounded, and free of intermediate overflow: hypot(x, y) * 2^F is the square root of the sum of the squared raw values, which is formed as an exact 256 bit integer. Spelled as sqrt(sqr(x) + sqr(y)) instead, it overflowed as soon as |x| or |y| reached 2^(I/2), long before the result itself leaves the range.
| x | First value |
| y | Second value |
Definition at line 2859 of file fixed_point128.h.
|
friend |
Calculates the square of a value. i.e. x^2.
Faster than x * x and bit identical to it. Prefer this function wherever a value is multiplied by itself, see fixed_point128::square().
| x | Value to square |
Definition at line 2887 of file fixed_point128.h.
|
friend |
Calculates the left zero count of value x, ignoring the sign. Counted on the magnitude, so a negative value gives the same answer as its opposite rather than the zero its two's complement bits would produce.
| x | input value. |
Definition at line 2895 of file fixed_point128.h.
|
friend |
Calculates the square root, correctly rounded.
sqrt(x) * 2^F is the square root of the raw value scaled up by another F bits, which makes it the integer square root of a 256 bit number: RoundedSqrt256() computes it rounded to nearest, so the result is the representable value closest to the exact root at every I and every magnitude. (A tie between two representable values cannot occur.)
| x | Value to calculate the root of |
| iterations | Ignored. It used to set the step count of an iterative refinement, which lost up to half of the integer bits for a large argument; it is kept so that existing calls still compile. |
Definition at line 2915 of file fixed_point128.h.
|
friend |
Factorial reciprocal (inverse). Calculates 1 / x! Maximum value of x that may produce non zero values is 34. This value depends on the amount of fraction bits. The table is parsed from decimal strings, so it carries the accuracy of the string constructor: within 0.5 + 23 / 2^(I-1) ulp of the exact 1 / x!, measured 17.5 ulp at I = 1 and 0.5 from I = 16 up.
| x | Input value |
| res | Result of the function |
Definition at line 2945 of file fixed_point128.h.
|
friend |
Calculates the reciprocal of a value. y = 1 / x.
Correctly rounded: the quotient comes from the same long division operator/=() uses, rounded to nearest with a tie going away from zero. The division is the faster of the two since div_128bit, and the Newton refinement of a double estimate this replaced lost accuracy as 1 / x grew - tens of thousands of ulp at fixed_point128<16>. It is called directly rather than through operator/=(), which divides by multiplying with this function when FP128_USE_RECIPROCAL_FOR_DIVISION is set.
| x | Input value |
Definition at line 3006 of file fixed_point128.h.
|
friend |
Calculate Sine and Cosine using CORDIC using a limited range of [-pi/2, pi/2] 64 iterations, one per entry of the arctangent table, which give an absolute accuracy of about 2^-63: measured within 1.1e-19 of mpmath for |x| < 1. The table used to skip arctan(2^-62), which held the error near 1.8e-19. Not used by tan(), which divides sin() by cos().
| x | |
| sin_x | Result of the Sine of x. |
| cos_x | Result of the Cosine of x. |
| apply_scale_factor | Apply a scale factor when 60 or more iterations are performed. This is required to get accurate results when the number of iterations is high, but it can be disabled for performance reasons when the number of iterations is low. |
Definition at line 3041 of file fixed_point128.h.
|
friend |
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! The series runs in a wider fraction than this instantiation has, see TrigSeries().
| x | value in Radians in the range [-0.5pi, 0.5pi] |
Definition at line 3185 of file fixed_point128.h.
|
friend |
Calculate the cosine function over a limited range [-0.5pi, 0.5pi] Using the Maclaurin series expansion, the formula is: x^2 x^4 x^6 cos(x) = 1 - — + — - — + ... 2! 4! 6! Evaluated directly rather than as sin1(pi/2 - x), which carried the rounding error of pi/2 into every result; cos1(0) is now exactly one. See TrigSeries().
| x | value in Radians in the range [-0.5pi, 0.5pi] |
Definition at line 3206 of file fixed_point128.h.
|
friend |
Calculate the Sine function Ultimately uses sin1() or cos1() with a reduced range of [-pi/4, pi/4].
Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 2.5 ulp for |x| < 4 (1.4 ulp from I = 16 up). Beyond that the reduction x - n * pi/2 adds n times the rounding error of pi/2 in this instantiation, at most |x| / 3 ulp more: 320 ulp for |x| near 1000 at I = 32.
| x | value in Radians |
Definition at line 3224 of file fixed_point128.h.
|
friend |
Calculate the inverse sine function Newton's method on sin() for |x| up to one half, see AsinNewton(). Beyond that the identity asin(x) = pi/2 - 2 asin(sqrt((1 - x) / 2)) keeps the iteration away from pi/2, where the derivative it divides by vanishes and the refinement stalled at double precision: asin(1) was 4e16 ulp off at fixed_point128<16>. The square root is correctly rounded, so the identity costs a few ulp at most.
Accuracy, measured against mpmath at I = 4, 16, 32, 62 and 63: within 3.5 ulp.
| x | value in radians in the range [-1,1] |
Definition at line 3257 of file fixed_point128.h.
|
friend |
Calculate the cosine function Ultimately uses sin1() or cos1() with a reduced range of [-pi/4, pi/4]. cos(0) is exactly one.
Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 1.8 ulp for |x| < 4 (1.3 ulp from I = 16 up), plus at most |x| / 3 ulp of argument reduction beyond, see sin().
| x | value in Radians |
Definition at line 3283 of file fixed_point128.h.
|
friend |
Calculate the inverse cosine function pi/2 - asin(x) for |x| up to one half. Beyond that acos(x) = 2 asin(sqrt((1 - x) / 2)) for a positive x and pi - 2 asin(sqrt((1 + x) / 2)) for a negative one, which keep Newton's method away from the ends of the domain: acos(-1) was 8e16 ulp off at fixed_point128<16>.
Accuracy, measured against mpmath at I = 4, 16, 32, 62 and 63: within 4 ulp.
| x | value in radians in the range [-1,1] |
Definition at line 3314 of file fixed_point128.h.
|
friend |
Calculate the tangent function tan(x) = sin(x)/cos(x)
The error of the cosine is divided by the cosine itself, so it grows towards the poles. Measured against mpmath for |x| < 4 at I = 4, 16, 32, 62 and 63: within 45 * max(1, |tan(x)|) ulp.
| x | value |
Definition at line 3339 of file fixed_point128.h.
|
friend |
Calculate the inverse tangent function Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 2.2 ulp.
| x | value |
Definition at line 3365 of file fixed_point128.h.
|
friend |
Calculate the inverse tangent function of the ratio y / x Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 3.3 ulp.
| y | value |
| x | value |
Definition at line 3414 of file fixed_point128.h.
|
friend |
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 Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 10 * max(1, |sinh(x)|) ulp at I = 4 and 3 * max(1, |sinh(x)|) ulp from I = 16 up. e^x itself has to fit the range, so a result between 2^(I-1) and 2^I overflows.
| x | value |
Definition at line 3460 of file fixed_point128.h.
|
friend |
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. The root is exact before it is rounded (RootOfSquareAndOne()) and the sum is kept from overflowing (LogOfSum()), so every argument works, lowest() included. Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 over the whole range: within 2.8 ulp.
| x | value |
Definition at line 3503 of file fixed_point128.h.
|
friend |
Calculate the hyperbolic cosine function e^x + e^(-x) cosh(x) = ---------— 2 Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 10 * max(1, cosh(x)) ulp at I = 4 and 3 * max(1, cosh(x)) ulp from I = 16 up. e^|x| itself has to fit the range, see sinh().
| x | value |
Definition at line 3521 of file fixed_point128.h.
|
friend |
Calculates the inverse hyperbolic cosine For x >= 1: acosh(x) = log(x + sqrt(x^2 - 1)) For x < 1, the function return zero Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 over the whole range: within 2.9 ulp. It was out by up to 5e8 ulp just above one, where x^2 - 1 cancels.
| x | value in the range [1, inf] |
Definition at line 3559 of file fixed_point128.h.
|
friend |
Calculates the hyperbolic tangent e^x - e^(-x) 1 - e^(-2|x|) tanh(x) = ---------— = ------------—, with the sign of x e^x + e^(-x) 1 + e^(-2|x|) The second form is the one evaluated, for every argument. Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 4.2 ulp.
| x | value |
Definition at line 3579 of file fixed_point128.h.
|
friend |
Calculates the inverse hyperbolic tangent 1 + x atanh(x) = 0.5 * log( --—) = 0.5 * (log(1 + x) - log(1 - x)) 1 - x The second form is the one evaluated. Both of its logarithms take an argument in (0, 2), inside the range of every instantiation, while the quotient of the first form leaves the range as x approaches one - beyond 0.88 at fixed_point128<4>, within 2^-15 of one at fixed_point128<16> - and the wrapped value made log() throw out of this noexcept function, terminating the process. Accuracy, measured against mpmath at I = 4, 16, 32, 62 and 63: within 1.4 ulp. Below I = 4 the same holds where log(1 - x) fits the range, which log() needs for its log2 (see log()): for |x| up to 0.75 at I = 1 and 0.9375 at I = 2.
| x | value in the range (-1, 1) |
Definition at line 3612 of file fixed_point128.h.
|
friend |
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. A negative x works with 1/e and the alternating series of e^-fx, so it never forms e^|x|.
Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 6.2 * max(1, e^x) ulp. The argument itself is only known to half an ulp, which alone moves a large result by e^x / 2 ulp.
| x | A number specifying a power. |
Definition at line 3645 of file fixed_point128.h.
|
friend |
Calculates the exponent of x and reduces 1 from the result: (e^x) - 1 Evaluated as exp(x) - 1, which in a fixed point type loses nothing to cancellation: the absolute error is that of exp(), within 9.3 * max(1, |e^x - 1|) ulp measured at I = 4 and 6.2 * max(1, e^x) ulp from I = 16 up.
| x | A number specifying a power. |
Definition at line 3699 of file fixed_point128.h.
|
friend |
Computes 2 to the power of x exp(x * ln(2)), the constant applied with 128 fraction bits. Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 5.5 * max(1, 2^x) ulp.
| x | Exponent value |
Definition at line 3711 of file fixed_point128.h.
|
friend |
Computes x to the power of y exp(y * log(x)). Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 7.3 * max(1, x^y) ulp at I = 4 and 4.4 * max(1, x^y) ulp from I = 16 up. Exact powers are not exact: pow(2, 3) is 8 - 15 ulp at I = 16. y * log(x) has to fit the range.
| x | Base value, must be positive |
| y | Exponent value |
Definition at line 3732 of file fixed_point128.h.
|
friend |
Calculates the Log base 2 of x: y = log2(x) Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 2 ulp at I = 1, 1.7 ulp at I = 2 and 1.1 ulp from I = 4 up. The compile time evaluation takes a different, bitwise path that truncates instead: it can be one ulp below the runtime result. A result outside the range wraps, which a narrow instantiation meets for small arguments: log2(x) needs x >= 2^(-2^I).
| x | The number to perform log2 on. |
Definition at line 3767 of file fixed_point128.h.
|
friend |
Calculates the natural Log (base e) of x: log(x) log2(x) * ln(2), the constant applied with 128 fraction bits by MulByFraction128() - a constant held to this instantiation's F bits, multiplied by a log2 of up to 63, would cost tens of ulp. Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 1.9 ulp. log2(x) has to fit the range as well, so a narrow instantiation cannot take the log of an argument below 2^(-2^I) even when its log would fit: at I = 1 that is x below 0.25.
| x | The number to perform log on. |
| std::domain_error | when x is zero or negative. |
Definition at line 3812 of file fixed_point128.h.
|
friend |
Calculates the natural Log (base e) of 1 + x: log(1 + x) Not noexcept: it forwards to log(), which rejects a non positive argument. Marking it noexcept would turn that domain_error into a call to std::terminate. 1 + x is exact in a fixed point type, so the error is that of log(): within 1.2 ulp measured, with log()'s limit on small arguments at I < 7.
| x | The number to perform log on. |
| std::domain_error | when x is -1 or below. |
Definition at line 3832 of file fixed_point128.h.
|
friend |
Calculates Log base 10 of x: log10(x) log2(x) * log10(2), the constant applied with 128 fraction bits, see log(). Accuracy, measured against mpmath at I = 1, 2, 4, 16, 32, 62 and 63 where the function exists: within 1 ulp, with log()'s limit on small arguments at I < 7.
| x | The number to perform log on. |
Definition at line 3840 of file fixed_point128.h.
|
friend |
Calculates Log base 2 of x as an integer ignoring the sign of x. floor(log2(fabs(x))), as the C function: logb(-8) is 3. A narrow instantiation cannot hold the exponent of its smallest values - logb(epsilon()) is -126 for fixed_point128<1> - and the result then wraps like any other overflow.
| x | The number to perform log on. |
| std::domain_error | when x is zero. The C function returns minus infinity for it, which this type cannot represent. |
Definition at line 3862 of file fixed_point128.h.
|
staticconstexpr |
Fraction bit count (127 - I). The remaining bit is the sign.
Definition at line 322 of file fixed_point128.h.
|
staticconstexpr |
Largest representable positive integer, 2^I - 1.
Definition at line 581 of file fixed_point128.h.