Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slight rounding errors in constants #3145

Open
jachymb opened this issue Feb 13, 2025 · 0 comments
Open

Slight rounding errors in constants #3145

jachymb opened this issue Feb 13, 2025 · 0 comments

Comments

@jachymb
Copy link

jachymb commented Feb 13, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant