Unexpected results converting finite `decimal128_t` to `double`
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 22/100
Research direction
The conversion is the static_cast<double> operator on decimal128_t in the boost/decimal headers; locate it with a search for the conversion operator and the decimal128_t type. Reproduce by casting the six listed inputs and comparing against the expected doubles in the table. Done means all six cases match IEEE round-to-nearest-even results, including the overflow to infinity, the underflow to signed zero, and the subnormal case.
Written by the indexing model from the issue text.
Description
static_cast<double>(boost::decimal::decimal128_t) gives the following results on a binary64 platform with round-to-nearest, ties-to-even. All six inputs are finite and exactly representable in decimal128_t:
| Exact input | Expected double |
Actual double |
|---|---|---|
1e1000 |
+∞ |
+0 |
-1e1000 |
−∞ |
+0 |
-1e-1000 |
−0 |
+0 |
5e-324 |
0x0.0000000000001p-1022 |
+0 |
9007199254740993 |
9007199254740992 |
9007199254740994 |
1.0000000000000001111 |
0x1.0000000000001p+0 |
1.0 |
The last two cases distinguish two rounding errors:
9007199254740993is exactly halfway between adjacent doubles; the lower neighbor has even significand and should be selected.1.0000000000000001111is strictly above the midpoint between1.0and its successor, so it should round up irrespective of the tie-breaking rule.
All six cases failed identically with Boost 1.92.0, master at 1f199e5, and develop at 215bbf0, using Apple Clang 21.0.0 on arm64 macOS 26.7.2.
- Dominant language
- C++
- Stars
- 67
- Forks
- 16
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 12
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/decimal
-
The decimal types have no operator<=> with GCC and Clang if no earlier header includes <compare>Possibly taken @ibmibmibm claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 25/100
Maintainers usually reply within 1 day
-
comparetotal gives incorrect results for NaN operandsPossibly taken @ibmibmibm claimed this 1 day ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 25/100
Maintainers usually reply within 1 day
-
A comparison of a decimal and an integer gives incorrect resultsPossibly taken @ibmibmibm claimed this 1 day ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 22/100
Maintainers usually reply within 1 day
-
A comparison of two decimal types can use the type with fewer digitsPossibly taken @ibmibmibm claimed this 1 day ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 20/100
Maintainers usually reply within 1 day
-
sinh, cosh, tanh, expm1 and exp2 give incorrect results, and 0 or infinity for some finite resultsPossibly taken @ibmibmibm claimed this 7 days ago. Open
Difficulty 5/5 Over a week Newbie friendliness 10/100
Maintainers usually reply within 1 day
All issues in boostorg/decimal
Similar issues
-
agent:WSL code-review linux pri:medium refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
kind/enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
psi29a/d2decomped#691 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
CachyOS/packageinstaller#144 ·
Maintainers usually reply within 1 day
-
(S1 - Need confirmation)
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
CleverRaven/Cataclysm-DDA#89715 ·
Maintainers usually reply within 1 day