numpy / numpy/numpy-quaddtype

BUG: inter-backend casts lose precision by converting through double

Open
#112 0 comments 0 reactions 1 assignee View on GitHub

@SwayamInSync is already working on this.

Since Jul 25, 2026.

bug
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 -> SLEEF preserves every long-double value exactly.
  • SLEEF -> long double is 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

Open the contributing guide

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.