math icon indicating copy to clipboard operation
math copied to clipboard

Slight rounding errors in constants

Open jachymb opened this issue 10 months ago • 0 comments

In constants.hpp, I noticed there are some constants that get a small unnecessary rounding error due to how they are defined.

For example, with 64bit precision floating point, we have:

LOG_TWO_PI = LOG_TWO + LOG_PI = 0.6931471805599453 + 1.1447298858494002 = 1.8378770664093453

However, a mathematically more precise value is $\log(2\pi) \approx 1.83787706640934548356065947281123527972279494727556682563430308096553139185$

This is better rounded to the 64bit value

1.8378770664093456

which means the current value has an unnecessary error in the order of E-16.

I guess there could be a similar type of issue for other constants as well.

I suppose this is pretty much negligible for any practical purpose and perhaps one may argue the current implementation is better readable. But my OCD is kinda forcing me to point this out haha

jachymb avatar Feb 13 '25 12:02 jachymb