Trees | Indices | Help |
|
---|
|
ieeefloat a set of functions for dealing with IEEE-754 float objects.
On most platforms Python uses IEEE-754 double objects of length 64 bits to represent floats (some architectures such as older Crays and Vaxes don't). Thus an IEEE-754 double is the implementation of a python float object on most platforms.
IEEE-74 uses special bit patterns to represent the following states or classes of IEEE floating point numbers (IEEE-class):
This module provides functions for working with python floats and their special values, if they contain IEEE-754 formatted values. Specifically:
It also provides constants containg specific bit patterns for NaN and +-inf as these values cannot be generated from strings via the constructor float(x) with some compiler implementations (typically older Microsoft Windows compilers).
As a convenience the names of functions and constants conform to those defined in the draft python PEP 754 'IEEE 754 Floating Point Special Values'.
Notes:
IEEE-754 double format:
Todo:
|
|||
|
|||
int |
|
||
float |
|
||
str |
|
||
list of str |
|
||
bit |
|
||
bool |
|
||
bool |
|
||
bool |
|
||
bool |
|
||
|
|||
bool |
|
||
list of 7 bytes |
|
||
list of 2 bytes |
|
||
bool |
|
||
bool |
|
||
bool |
|
||
bool |
|
||
bool |
|
||
bool |
|
||
bool |
|
||
float |
|
||
int |
|
|
|||
SIGNBIT = 128 Bit pattern for the sign bit in byte 8 0b00000001 of a IEEE-754 double. |
|||
EXPONENT_ALL_ONES_BYTE_1 = 127 Value of the first byte (byte 8) in the mantissa of a IEEE-754 double that is all ones (0b11111110). |
|||
EXPONENT_ALL_ONES_BYTE_0 = 240 Value of the second byte (byte 7) in the mantissa of a IEEE-754 double that is all ones (0b00001111). |
|||
MANTISSA_NIBBLE_MASK = 15 Mask to select the bits from the first nibble of byte 7 of an IEEE-754 which is part of the mantissa (0b00001111). |
|||
EXPONENT_NIBBLE_MASK = 240 Mask to select the bits from the second nibble of byte 7 of an IEEE-754 which is part of the exponent (0b11110000). |
|||
EXPONENT_SIGN_MASK = 127 Mask to select only bits from byte 8 of an IEEE-754 double that are not part of the sign bit (0b11111110). |
|||
CLASS_POS_INF = 1
|
|||
CLASS_NEG_INF = 2
|
|||
CLASS_POS_NORMAL = 4
|
|||
CLASS_NEG_NORMAL = 8
|
|||
CLASS_POS_DENORMAL = 16
|
|||
CLASS_NEG_DENORMAL = 32
|
|||
CLASS_QUIET_NAN = 64
|
|||
CLASS_SIGNAL_NAN = 128
|
|||
CLASS_POS_ZERO = 256
|
|||
CLASS_NEG_ZERO = 512
|
|||
NAN_BYTES =
Bytes for an arbitary IEEE-754 not a number (NaN) in little endian format 0b00000000 00000000 00000000 00000000 00000000 00000000 00011111 11111110. |
|||
INF_BYTES =
Bytes for IEEE-754 positive infinity (inf) in little endian format 0b00000000 00000000 00000000 00000000 00000000 00000000 00001111 11111110. |
|||
nan = nan One of a number of possible bit patterns used to represent an IEEE-754 double as a python float. |
|||
pos_inf = inf The value of a positive IEEE-754 double infinity as a python float. |
|||
neg_inf = -inf The value of a negative IEEE-754 double infinity as a python float. |
|||
PosZero = 0.0
|
|||
NegZero = -0.0
|
|||
PosEpsilonDenorm = 4.94065645841e-324
|
|||
NegEpsilonDenorm = -4.94065645841e-324
|
|||
PosEpsilonNorm = 2.22507385851e-308
|
|||
NegEpsilonNorm = -2.22507385851e-308
|
|||
PosMax = 1.79769313486e+308
|
|||
NegMin = -1.79769313486e+308
|
|||
PosInf = inf
|
|||
NegInf = -inf
|
|||
PosNaN_A = nan
|
|||
NegNaN_A = nan
|
|||
PosNaN_B = nan
|
|||
NegNaN_B = nan
|
|||
PosNaN_C = nan
|
|||
NegNaN_C = nan
|
|||
PosNaN = nan
|
|||
NegNaN = nan
|
|||
__package__ = None hash(x) |
Imports: pack, unpack, sys
|
Get the IEEE-class (NaN, inf etc) of a python float.
|
Pack 8 bytes into a python float. The function is endian aware and the data should be input in little endian format. Thus byte 8 contains the most significant bit of the exponent and the sign bit.
|
Pack a python float into a binary string. This function assumes that the python type float it represents a 64bit double of 8 bytes. This function reverses the resulting string if the current architecture is big endian.
|
Unpack a python float as a list of 8 bytes. This function assumes that the python type float it represents a 64bit double of 8 bytes.
|
Get the sign bit from a python float.
|
Test if a python float is positive.
|
Test if a python float 64 bit IEEE-74 double is negative.
|
Test to see if two python float are unordered. Float comparison is unordered if either or both of the objects is 'not a number' (NaN).
|
Test to see if a python float is finite. To be finite a number mustn't be a NaN or +/- inf. A result of True guarantees that the number is bounded by +/- inf, -inf < x < inf.
|
Copy the sign bit from one python float to another. This function is class agnostic the sign bit can be copied freely between ordinary floats, NaNs and +/- inf.
|
Check to see if a python float is denormalised. Denormalisation indicates that the number has no exponent set and all the precision is in the mantissa, this is an indication that the number is tending to towards underflow.
|
Get the 7 bytes that makeup the mantissa of float. The mantissa is returned as the 7 bytes in the mantissa in little endian order in the 7th byte the 2nd nibble of the byte is masked off as it contains part of the exponent. The second nibble of the 7th byte is therefore always has the value 0x0.
|
Get the 2 bytes that makeup the exponent of a float. The exponent is returned as the 2 bytes in the exponent in little endian order in the 2nd byte the last bit is masked off as this is the sign bit. Therefore all values have the last bit set to zero. In the first byte the first nibble of the byte is also masked off as it contains part of the mantissa and thus always has the value 0x0.
|
Check if the bits of the exponent of a float is zero.
|
Check if the bits of the mantissa of a float is zero.
|
Check if the bits of the exponent of a float is all 1 bits.
|
Check to see if a python float is an IEEE-754 double not a number (NaN).
|
Check to see if a python float is an infinity. The check returns true for either positive or negative infinities.
|
Check to see if a python float is positive infinity.
|
Check to see if a python float is negative infinity.
|
Convert a 64 bit IEEE-754 ascii bit pattern into a 64 bit Python float.
|
Convert a bit pattern into its integer representation.
|
|
nanOne of a number of possible bit patterns used to represent an IEEE-754 double as a python float. Do not use this value for comparisons of the form x==NaN as it will fail on some platforms use function isNaN instead.
|
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Apr 10 13:30:28 2013 | http://epydoc.sourceforge.net |