jakeret / hope

HOPE: A Python Just-In-Time compiler for astrophysical computations
GNU General Public License v3.0
382 stars 28 forks source link

Printing doubles #48

Closed wolfv closed 8 years ago

wolfv commented 8 years ago

While testing the library, I found that doubles are printed with less precision.

For example, np.pi is printed in the CPP with only 15 decimal places (it is defined with 35 in the numpy math header).

I tried to add {:.35} to the format string, which works but prints the number in pythons internal representation (ie. it's not the same as the one defined in the headers because of floating point issues, I guess).

Another alternative (for np.pi) would be to include numpy/npy_math.h and use NPY_PI as constant. However, that includes to add a String type to the ast.

Best,

Wolf

cosmo-ethz commented 8 years ago

Hi Wolf Thanks for reporting this. I think this is only related to PI and not a generic double-printing issue.

In HOPE we always use the value that is being returned from numpy.pi for the jit compilation (a float). As far as I know this type is mapped to a IEE754 double and we expect a 15–17 significant decimal digits precision