ieee-754

Why does (inf + 0j)*1 evaluate to inf + nanj?

Why does (inf + 0j)*1 evaluate to inf + nanj? Question: >>> (float(‘inf’)+0j)*1 (inf+nanj) Why? This caused a nasty bug in my code. Why isn’t 1 the multiplicative identity, giving (inf + 0j)? Asked By: marnix || Source Answers: The 1 is converted to a complex number first, 1 + 0j, which then leads to …

Total answers: 4

IEEE-754 Python

IEEE-754 Python Question: How can I convert a number with a decimal part to the simple precision system of the IEEE-754 in python in such a way that I enter the number and I throw the standard sign, exponent and mantissa? Example Input: 10.27 Example Output: 0 10000011 01001000101000111101011 Sign-Exponent-Mantissa Here is my attempt to …

Total answers: 3

On the float_precision argument to pandas.read_csv

On the float_precision argument to pandas.read_csv Question: The documentation for the argument in this post’s title says: float_precision : string, default None Specifies which converter the C engine should use for floating-point values. The options are None for the ordinary converter, high for the high-precision converter, and round_trip for the round-trip converter. I’d like to …

Total answers: 2

Why does the floating-point value of 4*0.1 look nice in Python 3 but 3*0.1 doesn't?

Why does the floating-point value of 4*0.1 look nice in Python 3 but 3*0.1 doesn't? Question: I know that most decimals don’t have an exact floating point representation (Is floating point math broken?). But I don’t see why 4*0.1 is printed nicely as 0.4, but 3*0.1 isn’t, when both values actually have ugly decimal representations: …

Total answers: 4

Why `0.4/2` equals to `0.2` meanwhile `0.6/3` equals to `0.19999999999999998` in python?

Why `0.4/2` equals to `0.2` meanwhile `0.6/3` equals to `0.19999999999999998` in python? Question: I know these are float point division. But why did these two formula behave differently? And I did some more investigation, the result confusing me even more: >>>0.9/3 0.3 >>>1.2/3 0.39999999999999997 >>>1.5/3 0.5 What’s the logic here to decide whether the result …

Total answers: 3

Reading 32 bit signed ieee 754 floating points from a binary file with python?

Reading 32 bit signed ieee 754 floating points from a binary file with python? Question: I have a binary file which is simple a list of signed 32 bit ieee754 floating point numbers. They are not separated by anything, and simply appear one after another until EOF. How would I read from this file and …

Total answers: 4