View Source z_mochinum (zotonic_stdlib v1.23.1)

Useful numeric algorithms for floats that cover some deficiencies in the math module. More interesting is digits/1, which implements the algorithm from: http://www.cs.indiana.edu/~burger/fp/index.html See also "Printing Floating-Point Numbers Quickly and Accurately" in Proceedings of the SIGPLAN '96 Conference on Programming Language Design and Implementation.

Summary

Functions

Returns a string that accurately represents the given integer or float using a conservative amount of digits. Great for generating human-readable output, or compact ASCII serializations for floats.

Return the fractional and exponent part of an IEEE 754 double, equivalent to the libc function of the same name. F = Frac * pow(2, Exp).

Return the ceiling of F as an integer. The ceiling is defined as F when F == trunc(F); trunc(F) when F < 0; trunc(F) + 1 when F > 0.

Moderately efficient way to exponentiate integers. int_pow(10, 2) = 100.

Functions

digits(N)

Returns a string that accurately represents the given integer or float using a conservative amount of digits. Great for generating human-readable output, or compact ASCII serializations for floats.

frexp(F)

Return the fractional and exponent part of an IEEE 754 double, equivalent to the libc function of the same name. F = Frac * pow(2, Exp).

int_ceil(X)

Return the ceiling of F as an integer. The ceiling is defined as F when F == trunc(F); trunc(F) when F < 0; trunc(F) + 1 when F > 0.

int_pow(X, N)

Moderately efficient way to exponentiate integers. int_pow(10, 2) = 100.