Skip to content

Round a short decimal128_t product near the smallest exponent - #1483

Draft
ibmibmibm wants to merge 1 commit into
boostorg:developfrom
ibmibmibm:worktree-d128-mul-subnormal
Draft

ibmibmibm wants to merge 1 commit into
boostorg:developfrom
ibmibmibm:worktree-d128-mul-subnormal

Conversation

@ibmibmibm

Copy link
Copy Markdown
Contributor
  • The decimal128_t multiply has a separate path for an exponent sum below -6142. It does not
    expand the significands, so the product can have 1 to 68 digits.
  • The path rounded the product only above 38 digits, the digits10 of the 128-bit significand
    type. A product of 35 to 38 digits then went to pack_in_range unrounded. The encoder wrote
    its extra digits into bits outside the significand field.
  • The limit is now detail::precision_v<ReturnType>, 34 digits for decimal128_t.
  • The new test github_issue_1482.cpp multiplies products of 35 to 38 digits in each rounding
    mode. Before the change, each check fails except one product that rounds to zero.

A sweep of 20000 such products gives 962 wrong results in each of the five rounding modes on
develop, and none after the change. The change needs #1477, which is in develop. Issue
#1482 gives the values, the sweep, the comparison with develop and the benchmark.

Fixes #1482

@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.8%. Comparing base (c4e5174) to head (edb1ee2).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #1483     +/-   ##
=========================================
+ Coverage     98.7%   98.8%   +0.1%     
=========================================
  Files          315     316      +1     
  Lines        26449   26473     +24     
  Branches      2253    2253             
=========================================
+ Hits         26104   26129     +25     
+ Misses         345     344      -1     
Files with missing lines Coverage Δ
include/boost/decimal/detail/mul_impl.hpp 95.2% <100.0%> (ø)
test/github_issue_1482.cpp 100.0% <100.0%> (ø)

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c4e5174...edb1ee2. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ibmibmibm
ibmibmibm force-pushed the worktree-d128-mul-subnormal branch from 5f9b773 to 10727e1 Compare October 1, 2026 13:44
- The decimal128_t multiply has a separate path for an exponent sum near
  the smallest exponent. It does not expand the significands, so the
  product can have 1 to 68 digits.
- The path rounded the product only above 38 digits, the digits10 of the
  128-bit significand type. A product of 35 to 38 digits then went to
  pack_in_range unrounded, and its extra digits broke the encoding.
- The limit is now the precision of the type, 34 digits.
- The new test github_issue_1482.cpp multiplies products of 35 to 38
  digits in each rounding mode.
@ibmibmibm
ibmibmibm force-pushed the worktree-d128-mul-subnormal branch from 10727e1 to edb1ee2 Compare October 1, 2026 16:08

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

A decimal128_t product of short operands near the smallest exponent is wrong

1 participant