Module dmochinum

Useful numeric algorithms for floats that cover some deficiencies in the math module.

Copyright © 2007 Mochi Media, Inc.

Authors: Bob Ippolito (bob@mochimedia.com).

Description

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.

Function Index

digits/1 Returns a string that accurately represents the given integer or float using a conservative amount of digits.
frexp/1 Return the fractional and exponent part of an IEEE 754 double, equivalent to the libc function of the same name.
int_ceil/1 Return the ceiling of F as an integer.
int_pow/2 Moderately efficient way to exponentiate integers.

Function Details

digits/1

digits(N::number()) -> string()

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/1

frexp(F::float()) -> {Frac::float(), Exp::float()}

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/1

int_ceil(F::float()) -> integer()

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/2

int_pow(X::integer(), N::integer()) -> Y::integer()

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


Generated by EDoc