[Tutor] numerical problem

Ben Finney ben+python at benfinney.id.au
Tue Mar 4 04:56:57 CET 2014


Gabriele Brambilla <gb.gabrielebrambilla at gmail.com> writes:

> the values in www are like 1.01e-134 and also smaller, and I sum values
> like this: there could be any problem summing so small numbers?

The default floating-point number type in Python is a fixed-precision
float <URL:http://docs.python.org/3/library/stdtypes.html#typesnumeric>.

Yes, with the ‘float’ type calcuations will lose information, and
calculations at differing orders of magnitude will lose information
faster. That's a limitation of any fixed-precision float implementation.

If you want to use different types with different trade-offs, see
<URL:http://docs.python.org/3/library/stdtypes.html#typesnumeric> the
Python documentation and the NumPy documentation
<URL:http://docs.scipy.org/doc/numpy/user/basics.types.html> for the
numeric data types they support.

-- 
 \           “If [a technology company] has confidence in their future |
  `\      ability to innovate, the importance they place on protecting |
_o__)     their past innovations really should decline.” —Gary Barnett |
Ben Finney



More information about the Tutor mailing list