s2.util.math.exactfloat

Undocumented in source.

Members

Functions

abs
ExactFloat abs(ExactFloat a)
Undocumented in source. Be warned that the author may not have intended to support it.
ceil
ExactFloat ceil(ExactFloat a)

///// Integer rounding functions that return ExactFloat values. Round up to the nearest integer.

copysign
ExactFloat copysign(ExactFloat a, ExactFloat b)

Return an ExactFloat with the magnitude of "a" and the sign bit of "b". (Note that an IEEE zero can be either positive or negative.)

drem
ExactFloat drem(ExactFloat a, ExactFloat b)

A synonym for remainder().

fabs
ExactFloat fabs(ExactFloat a)

/////////////////////////////////////////////////////////////////// ///// Miscellaneous simple arithmetic functions. Absolute value.

fdim
ExactFloat fdim(ExactFloat a, ExactFloat b)

Positive difference: max(a - b, 0).

floor
ExactFloat floor(ExactFloat a)

Round down to the nearest integer.

fmax
ExactFloat fmax(ExactFloat a, ExactFloat b)

Maximum of two values.

fmin
ExactFloat fmin(ExactFloat a, ExactFloat b)

Minimum of two values.

fmod
ExactFloat fmod(ExactFloat a, ExactFloat b)

///// Remainder functions. The remainder of dividing "a" by "b", where the quotient is rounded toward zero to the nearest integer. Similar to (a - trunc(a / b) * b).

frexp
ExactFloat frexp(ExactFloat a, int exp)

Convert "a" to a normalized fraction in the range \[0.5, 1\) times a power of two. Return the fraction and set "exp" to the exponent. If "a" is zero, infinity, or NaN then return "a" and set "exp" to zero.

ilogb
int ilogb(ExactFloat a)

Convert "a" to a normalized fraction in the range \[1,2\) times a power of two, and return the exponent value as an integer. This is equivalent to lrint(floor(log2(fabs(a)))) but it is computed more efficiently. Returns the constants documented in the man page for zero, infinity, or NaN.

ldexp
ExactFloat ldexp(ExactFloat a, int exp)

Return "a" multiplied by 2 raised to the power "exp".

logb
ExactFloat logb(ExactFloat a)

Convert "a" to a normalized fraction in the range \[1,2\) times a power of two, and return the exponent value as an ExactFloat. This is equivalent to floor(log2(fabs(a))) but it is computed more efficiently.

lrint
long lrint(ExactFloat a)

///// Integer rounding functions that return C++ integer types. Like rint(), but rounds to the nearest "long" value. Returns the minimum/maximum possible integer if the value is out of range.

lround
long lround(ExactFloat a)

Like round(), but rounds to the nearest "long" value. Returns the minimum/maximum possible integer if the value is out of range.

modf
ExactFloat modf(ExactFloat a, ExactFloat i_ptr)

Break the argument "a" into integer and fractional parts, each of which has the same sign as "a". The fractional part is returned, and the integer part is stored in the output parameter "i_ptr". Both output values are set to have the same maximum precision as "a".

nearbyint
ExactFloat nearbyint(ExactFloat a)

A synonym for rint().

remainder
ExactFloat remainder(ExactFloat a, ExactFloat b)

The remainder of dividing "a" by "b", where the quotient is rounded to the nearest integer, rounding halfway cases to an even integer. Similar to (a - rint(a / b) * b).

rint
ExactFloat rint(ExactFloat a)

Round to the nearest integer, rounding halfway cases to an even integer. For example: f(-0.5) = 0, f(0.5) = 0, f(1.5) = 2, f(2.5) = 2.

round
ExactFloat round(ExactFloat a)

Round to the nearest integer, rounding halfway cases away from zero. For example: f(-0.5) = -1, f(0.5) = 1, f(1.5) = 2, f(2.5) = 3.

scalbln
ExactFloat scalbln(ExactFloat a, long exp)

A version of ldexp() where "exp" is a long integer.

scalbn
ExactFloat scalbn(ExactFloat a, int exp)

A synonym for ldexp().

trunc
ExactFloat trunc(ExactFloat a)

Round to the nearest integer not larger in absolute value. For example: f(-1.9) = -1, f(2.9) = 2.

Structs

ExactFloat
struct ExactFloat

ExactFloat is a multiple-precision floating point type based on the OpenSSL Bignum library. It has the same interface as the built-in "float" and "double" types, but only supports the subset of operators and intrinsics where it is possible to compute the result exactly. So for example, ExactFloat supports addition and multiplication but not division (since in general, the quotient of two floating-point numbers cannot be represented exactly). Exact arithmetic is useful for geometric algorithms, especially for disambiguating cases where ordinary double-precision arithmetic yields an uncertain result.

Meta