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

Incorrect numeric_limits::max #794

Open
libbooze opened this issue Jan 18, 2025 · 1 comment · May be fixed by #796
Open

Incorrect numeric_limits::max #794

libbooze opened this issue Jan 18, 2025 · 1 comment · May be fixed by #796
Assignees
Labels
Boost Review Collected Comments from Boost Review Period Bug Something isn't working

Comments

@libbooze
Copy link

I could be wrong, but it seems to be a bug.

When I do:

--- a/include/boost/decimal/decimal64.hpp
+++ b/include/boost/decimal/decimal64.hpp
...
-    static constexpr auto (max)        () -> boost::decimal::decimal64 { return {9'999'999'999'999'999, max_exponent}; }
+    static constexpr auto (max)        () -> boost::decimal::decimal64 { return {9'999'999'999'999'999, max_exponent-16}; }

I get correct value:
max: 9.99999999999999900000e+384

with original code I get infinity.

by correct I mean what https://www.open-std.org/JTC1/SC22/WG21/docs/papers/2009/n2849.pdf specifies:

Expansion: an rvalue of type decimal64 equal to the maximum finite number that can
be represented by an object of type decimal64; exactly equal to 9.999999999999999 x 10^384 (there are fifteen 9's after the decimal point)

This is just for decimal64, others have same issue.

I think adding test that uses "excessive" precision(e.g. std::print("max: {:.30e}\n", nl::max()); ) to print numeric limits might be useful since I literally copy/pasted the value from PDF(
9.999999999999999) into find of my output window and I saw that after fix above output matches(all digits after those nines were zero and exponent matched).

@mborland mborland added Bug Something isn't working Boost Review Collected Comments from Boost Review Period labels Jan 18, 2025
@mborland mborland self-assigned this Jan 18, 2025
@mborland
Copy link
Member

I believe you are right. Will fix shortly.

@mborland mborland linked a pull request Jan 18, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Boost Review Collected Comments from Boost Review Period Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants