I am getting the following unexpected result when I do arithmetic with small numbers in Python:
>>> sys.float_info
sys.float_info(max=1.797693134862
it should be able to handle "large" small numbers like 1e-17, shouldn't it?
Not necessarily (it depends on the numbers). A float
cannot exactly represent either 1e-17
or 1-(1e-17)
. In the case of the latter, the nearest number that it can represent is 1
.
I suggest you read What Every Computer Scientist Should Know About Floating-Point Arithmetic.