real operations imprecise?
WebFreak001
d.forum at webfreak.org
Tue May 5 13:44:18 UTC 2020
I was dumping the full PI value on my machine with the highest
precision it could get and got:
$ rdmd --eval='printf("%.70llf\n", PI)'
3.1415926535897932385128089594061862044327426701784133911132812500000000
now this all looks good, but when I tried to print PI_2 I got
$ rdmd --eval='printf("%.70llf\n", PI_2)'
1.5707963267948965579989817342720925807952880859375000000000000000000000
note how many more 0's there are.
When manually writing down the identifier as it is defined for PI
but with the exponent reduced by one it looks good again:
$ rdmd --eval='printf("%.70llf\n",
cast(real)0x1.921fb54442d18469898cc51701b84p+0L)'
1.5707963267948966192564044797030931022163713350892066955566406250000000
I would expect that the manifest constant PI_2 being defined as
PI/2 would simply modify the exponent and not the actual value in
such a drastic manner.
While I don't need it myself right now, is there some compiler
switch to make real operations like this division more precise to
not lose all these bits of information? (LDC 1.20.1)
Sure, 1^-50 precision might not be everyones typical use-case but
I think there is potential improvement either in the compiler or
std.math to be done here :p
More information about the Digitalmars-d-learn
mailing list