Skip to content

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

Description

@SwayamInSync

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions