Hybrid fixed-/floating-point numbers. More...
Functions | |
def | format |
Convert a floating-point number to its hybrid string representation. More... | |
def | parse |
Convert a hybrid string representation to a floating-point number. More... | |
Hybrid fixed-/floating-point numbers.
This module provides formatting and parsing functions for a hybrid number format which uses floating-point numbers as the base of a fixed-point notation. This way, decimal fractions down to an arbitrary (but fixed) number of digits can be represented exactly while still allowing the benefits from a floating-point number format.
As an example, in a format with three fixed digits, both the number 1
(represented as the floating-point value 1000.0
) and the number 0.001
(represented as the floating-point value 1.0
) can be represented exactly, whereas the number 0.0001
(represented as the floating-point number 0.1
) would be subject to conversion errors.
To avoid the usual errors when converting a floating-point number to a string and vice versa, hexadecimal notation is used for the decimals to the floating-point representation.
def xorn.hybridnum.format | ( | x, | |
decimal_digits | |||
) |
Convert a floating-point number to its hybrid string representation.
TODO: For efficiency reasons, this should probably be ported to C.
Definition at line 42 of file hybridnum.py.
def xorn.hybridnum.parse | ( | s, | |
decimal_digits | |||
) |
Convert a hybrid string representation to a floating-point number.
TODO: For efficiency reasons, this should probably be ported to C.
Definition at line 133 of file hybridnum.py.