0

Transformation of the "exact" values to float64() gives a "garbage" after the 16th significant digit (decimal places)

For example, the calculation "1/3"

import mpmath as mpm

import numpy as np

ma = mpm.mpf('1.')

mb = mpm.mpf('3.')

me = ma/mb

'{0:.33e} {1:.33e} {2:.33e}'.format(np.float64(ma),np.float64(mb),np.float64(me))

'1.000000000000000000000000000000000e+00  3.000000000000000000000000000000000e+00  3.333333333333333148296162562473910e-01'

How to set the number of actually calculated decimal places in numpy

Thank you

trashrobber
  • 727
  • 2
  • 9
  • 26
  • Does this answer your question? [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – Fred Larson Feb 27 '20 at 14:11
  • `float/float64` is only good for showing 16 decimal places. Look at `print(float(me))`. What do you see with `print(me)`? I believe `mpmath` has a way of setting the display precision. Trying to do so via `np.float64` and the `format` is wrong. – hpaulj Feb 27 '20 at 17:11
  • Look at `mpm.mp` and its docs. The default setting is 15 for display, and 53 for precision. So it doesn't make sense to display your `me` with anything beyond '{:.15e}'. http://mpmath.org/doc/current/basics.html#setting-the-precision – hpaulj Feb 27 '20 at 17:17
  • However, the goal was to use numpy because of the faster calculations. The number of significant digits is important. Why then need float64, float128, if the number of characters of the calculated accuracy is only 16??? This is a question about using float numpy. Question about HOW to make calculations with real float64 accuracy (more than 15 significant digits). How to get 0.(3) enstead 3.333333333333333148296162562473910e-01 using numpy – Alexander Pyhtin Feb 27 '20 at 18:19

0 Answers0