View Source z_mochinum (zotonic_stdlib v1.16.0)

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.

Link to this section 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.

Link to this section 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.