Module double
[show private | hide private]
[frames | no frames]

Module double

Support for IEEE 754 double-precision floating-point numbers. The purpose is to work around the woefully inadequate built-in floating-point support in Python. Functionality is a blend of the static members of java.lang.Double and bits of <float.h> and <math.h> from C99.
Function Summary
float copysign(x, y)
Return a floating-point number whose absolute value matches x and whose sign matches y.
long doubleToLongBits(value)
Similar to doubleToRawLongBits, but standardize NaNs.
long doubleToRawLongBits(value)
Return the IEEE 754 bit representation (64 bits as a long integer) of the given double-precision floating-point value.
float fdiv(x, y)
Divide two numbers according to IEEE 754 floating-point semantics.
str fpclassify(value)
Return a string indicating the classification of the given value as one of 'NAN', 'INFINITE', 'ZERO', 'SUBNORMAL', or 'NORMAL'.
bool isfinite(value)
Return True if the given value is a finite number; False if it is NaN or infinity.
bool isinf(value)
Return True if the given value represents positive or negative infinity; False otherwise.
bool isnan(value)
Return True if given value is not a number; False if it is a number.
bool isnormal(value)
Return True if the given value is a normal floating-point number; False if it is NaN, infinity, or a denormalized (subnormal) number.
float longBitsToDouble(bits)
Return the double-precision floating-point value corresponding to the given bit pattern bits.
bool signbit(value)
Test whether the sign bit of the given floating-point value is set.

Variable Summary
float EPSILON = 2.2204460492503131e-16                                                
float MAX_VALUE = 1.7976931348623157e+308                                               
float MIN_NORMAL = 2.2250738585072014e-308                                               
float MIN_VALUE = 4.9406564584124654e-324                                               
float NAN = nan                                                                   
float NEGATIVE_INFINITY = -inf                                                                  
float NEGATIVE_ZERO = -0.0                                                                  
float POSITIVE_INFINITY = inf                                                                   

Function Details

copysign(x, y)

Return a floating-point number whose absolute value matches x and whose sign matches y. This can be used to copy the sign of negative zero, as follows:
>>> copysign(1, NEGATIVE_ZERO)
-1.0
Parameters:
x - the floating-point number whose absolute value is to be copied
           (type=float)
y - the number whose sign is to be copied
           (type=number)
Returns:
a floating-point number whose absolute value matches x and whose sign matches y.
           (type=float)

Postconditions:

  • (isnan(result) and isnan(x)) or abs(result) == abs(x)
  • signbit(result) == signbit(y)

doubleToLongBits(value)

Similar to doubleToRawLongBits, but standardize NaNs.
Parameters:
value - a Python (double-precision) float value
           (type=float)
Returns:
the IEEE 754 bit representation (64 bits) of the given floating-point value if it is a number, or the bit representation of NAN if it is not a number.
           (type=long)

doubleToRawLongBits(value)

Parameters:
value - a Python (double-precision) float value
           (type=float)
Returns:
the IEEE 754 bit representation (64 bits as a long integer) of the given double-precision floating-point value.
           (type=long)

fdiv(x, y)

Divide two numbers according to IEEE 754 floating-point semantics.

Division by zero does not raise an exception, but produces negative or positive infinity or NaN as a result.
>>> fdiv(+1, +0.0) == POSITIVE_INFINITY
True

>>> fdiv(-1, +0.0) == NEGATIVE_INFINITY
True

>>> fdiv(+1, -0.0) == NEGATIVE_INFINITY
True

>>> fdiv(-1, -0.0) == POSITIVE_INFINITY
True

>>> isnan(fdiv(0.0, 0.0))
True
Parameters:
x - the dividend
           (type=number)
y - the divisor
           (type=number)
Returns:
the quotient x/y with division carried out according to IEEE 754 semantics.
           (type=float)

fpclassify(value)

Parameters:
value - a Python (double-precision) float value
           (type=float)
Returns:
a string indicating the classification of the given value as one of 'NAN', 'INFINITE', 'ZERO', 'SUBNORMAL', or 'NORMAL'.
           (type=str)

isfinite(value)

Parameters:
value - a Python (double-precision) float value
           (type=float)
Returns:
True if the given value is a finite number; False if it is NaN or infinity.
           (type=bool)

isinf(value)

Parameters:
value - a Python (double-precision) float value
           (type=float)
Returns:
True if the given value represents positive or negative infinity; False otherwise.
           (type=bool)

isnan(value)

Parameters:
value - a Python (double-precision) float value
           (type=float)
Returns:
True if given value is not a number; False if it is a number.
           (type=bool)

isnormal(value)

Parameters:
value - a Python (double-precision) float value
           (type=float)
Returns:
True if the given value is a normal floating-point number; False if it is NaN, infinity, or a denormalized (subnormal) number.
           (type=bool)

longBitsToDouble(bits)

Parameters:
bits - the bit pattern in IEEE 754 layout
           (type=long)
Returns:
the double-precision floating-point value corresponding to the given bit pattern bits.
           (type=float)

signbit(value)

Test whether the sign bit of the given floating-point value is set. If it is set, this generally means the given value is negative. However, this is not the same as comparing the value to 0.0. For example:
>>> NEGATIVE_ZERO < 0.0
False
since negative zero is numerically equal to positive zero. But the sign bit of negative zero is indeed set:
>>> signbit(NEGATIVE_ZERO)
True

>>> signbit(0.0)
False
Parameters:
value - a Python (double-precision) float value
           (type=float)
Returns:
True if the sign bit of value is set; False if it is not set.
           (type=bool)

Variable Details

EPSILON

Type:
float
Value:
2.2204460492503131e-16                                                

MAX_VALUE

Type:
float
Value:
1.7976931348623157e+308                                               

MIN_NORMAL

Type:
float
Value:
2.2250738585072014e-308                                               

MIN_VALUE

Type:
float
Value:
4.9406564584124654e-324                                               

NAN

Type:
float
Value:
nan                                                                   

NEGATIVE_INFINITY

Type:
float
Value:
-inf                                                                  

NEGATIVE_ZERO

Type:
float
Value:
-0.0                                                                  

POSITIVE_INFINITY

Type:
float
Value:
inf                                                                   

Generated by Epydoc 2.1 on Thu Feb 15 05:32:54 2007 http://epydoc.sf.net