[Numpy-discussion] Floating point question
Gideon Simpson
simpson at math.toronto.edu
Mon Mar 2 15:37:33 EST 2009
I recently discovered that for 8 byte floating point numbers, my
fortran compilers (gfortran 4.2 and ifort 11.0) on an OS X core 2 duo
machine believe the smallest number 2.220507...E-308. I presume that
my C compilers have similar results.
I then discovered that the smallest floating point number in python
2.5 is 4.9065...E-324. I have been using numpy to generate data,
saving it with savetxt, and then reading it in as ASCII into my
fortran code. Recently, it crapped out on something because it didn't
like reading it a number that small, though it is apparently perfectly
acceptable to python.
My two questions are:
1. What is the best way to handle this? Is it just to add a filter
of the form
u = u * ( np.abs(u) > 2.3 e-308)
2. What gives? What's the origin of this (perceived) inconsistency
in floating points across languages within the same platform?
I recognize that this isn't specific to Scipy/Numpy, but thought
someone here might have the answer.
-gideon
More information about the NumPy-Discussion
mailing list