BUG: inter-backend casts lose precision by converting through double
@SwayamInSync is already working on this.
Since Jul 25, 2026.
- Dominant language
- Python
- Stars
- 24
- Forks
- 6
- Avg merge
- 5d 41m
- Merged PRs (30d)
- 3
Description
Conversions between the SLEEF and long-double backends currently use double as an intermediate in quad_to_quad_strided_loop.
Examples from casts.cpp:
Sleef_cast_from_doubleq1(static_cast<double>(ld));
static_cast<long double>(cast_sleef_to_double(sleef));
This discards valid precision beyond binary64 in both directions. In particular, x87 long double has a 64-bit significand, while binary64 has only 53 bits.
A value such as 1 + 2**-60 is exactly representable by x87 long double and binary128, but is rounded to 1.0 by the current long-double -> SLEEF cast.
The casts should convert directly between the source and destination formats, preserving signed zero, finite values, subnormals, infinities, and signed NaNs. SLEEF -> long double may be narrowing, but it should round directly to the target format rather than first narrowing to double.
Acceptance criteria:
Long-double -> SLEEFpreserves every long-double value exactly.SLEEF -> long doubleis correctly rounded for the platform format.- No conversion passes through binary64.
- Boundary, subnormal, signed-zero, infinity, NaN, and precision-sensitive round-trip tests are included.
Contributor guide
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.
Assessment
This issue has not been assessed yet.