segpy.ibm_float module¶
-
class
segpy.ibm_float.
IBMFloat
¶ Bases:
numbers.Real
-
as_integer_ratio
()¶
-
exp16
¶ The base 16 exponent.
-
frexp
()¶ Obtain the fraction and exponent.
Returns: A pair where the first item is the fraction in the range -1.0 and +1.0 and the exponent is an integer such that f = fraction * 2**exponent
-
classmethod
from_bytes
(b)¶
-
classmethod
from_float
(f)¶ Construct an IBMFloat from an IEEE float.
Parameters: f (float) – The value to be converted.
Returns: An IBMFloat.
Raises: - OverflowError - If f is outside the representable range.
- ValueError - If f is NaN or infinite.
- FloatingPointError - If f cannot be represented without total loss of precision.
-
classmethod
from_float_without_underflow
(f)¶ Construct an IBMFloat from an IEEE float.
Parameters: f (float) – The value to be converted. If the provided IEEE value underflows the smallest representable IBM value, this function returns zero.
Returns: An IBMFloat.
Raises: - OverflowError - If f is outside the representable range.
- ValueError - If f is NaN or infinite.
-
classmethod
from_real
(f)¶
-
int_mantissa
¶
-
is_subnormal
()¶
-
is_zero
()¶
-
classmethod
ldexp
(fraction, exponent)¶ Make an IBMFloat from fraction and exponent.
The is the inverse function of IBMFloat.frexp()
Parameters: - fraction – A Real in the range -1.0 to 1.0.
- exponent – An integer in the range -256 to 255 inclusive.
-
normalize
()¶ Normalize the floating point representation.
Returns: A normalized IBMFloat equal in value to this object. Raises: FloatingPointError - If the number could not be normalized.
-
signbit
¶ True if the value is negative, otherwise False.
-
try_normalize
()¶ Normalize if possible.
If it is not possible to normalize the representation, it remains unmodified.
-
zero_subnormal
()¶
-
-
segpy.ibm_float.
ibm2ieee
(big_endian_bytes)¶ Interpret a byte string as a big-endian IBM float.
Parameters: big_endian_bytes (bytes) – A byte-string containing at least four bytes. Returns: The floating point value.
-
segpy.ibm_float.
ieee2ibm
(f)¶ Convert a float to four big-endian bytes representing an IBM float.
Parameters: f (float) – The value to be converted.
Returns: A bytes object (Python 3) or a string (Python 2) containing four bytes representing a big-endian IBM float.
Raises: - OverflowError - If f is outside the representable range.
- ValueError - If f is NaN or infinite.
- FloatingPointError - If f cannot be represented without total loss of precision.