Unexpected results converting finite `decimal128_t` to `double`

Open
#1,568 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
22/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c, cpp
Domain
cli, data

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:

  • 9007199254740993 is exactly halfway between adjacent doubles; the lower neighbor has even significand and should be selected.
  • 1.0000000000000001111 is strictly above the midpoint between 1.0 and 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/decimal

All issues in boostorg/decimal

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.