[Numpy-discussion] np.savetxt() default format

Oscar Benjamin oscar.j.benjamin at gmail.com
Mon Feb 24 09:09:57 EST 2014

On 24 February 2014 13:26, Daniele Nicolodi <daniele at grinta.net> wrote:
> Hello,
> I've noticed that numpy default format for saving data in ascii
> representation with np.savetxt() is "%.18e".  Given that the default
> data type for numpy is double and that the resolution of doubles is 15
> decimal digits, what's the reason of the the additional three digits?
> The three additional digits are definitely not an issue, but I would
> like to understand the reason why they are there.

It is reasonable to think of doubles as being limited to 15 decimal
digits when reasoning about rounding errors but that's a conservative

If you want to be able to round trip from IEEE-754 double precision to
decimal and back you need more than 15 digits. The difference between
1.0 and the next smallest double precision number appears only at the
16th decimal place:

>>> b = 1 + 1.0000000001*2**-53
>>> b
>>> len(repr(b)) - 2

I think the convention to use 18 digits generally stems from not fully
trusting the IEEE-754-ness of other systems that might read your data.


More information about the NumPy-Discussion mailing list