Repository navigation
libs/libm: support 128-bit quad-precision and universal fallback in truncl - #20682
Merged
acassis merged 1 commit intoOct 16, 2026
Merged
Conversation
Swatantra-66
requested review from
jerpelea and
xiaoxiang781216
as code owners
October 15, 2026 12:28
xiaoxiang781216
approved these changes
Oct 15, 2026
…runcl Previously, truncl() aborted the kernel with PANIC() on architectures where long double is not equal to double and LDBL_MANT_DIG != 64 (such as IEEE-754 binary128 quad-precision on RISC-V 64, AArch64, or SPARC with LDBL_MANT_DIG == 113). This commit: 1. Extends the musl bit-level branch to support LDBL_MANT_DIG == 113 (IEEE-754 quad-precision binary128) with proper big- and little-endian ldshape layouts. 2. Replaces PANIC() in the #else block with an IEEE-754 compliant mathematical fallback using copysignl((x >= 0.0) ? floorl(x) : ceill(x), x), guaranteeing that truncl() never crashes on any architecture. 3. Removes the unused assert.h include and adds endian.h in alphabetical order. Fixes: apache#18351 Signed-off-by: Swatantra Yadav <[email protected]>
Swatantra-66
force-pushed
the
fix/libm-truncl-quad-precision
branch
from
October 16, 2026 04:45
2e94bc6 to
b319514
Compare
acassis
approved these changes
Oct 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes: #18351
Resolves the unresolved
PANIC(); /* FIX ME */inlibs/libm/libm/lib_truncl.c.Previously,
truncl()aborted the kernel withPANIC()on any architecture wherelong doubleis not identical todoubleandLDBL_MANT_DIG != 64(e.g., IEEE-754binary128quad-precision on RISC-V 64, AArch64, or SPARC withLDBL_MANT_DIG == 113).This PR:
LDBL_MANT_DIG == 113):toint = 1 / LDBL_EPSILONbranch to support 128-bit floats.union ldshapedefinitions (matching the pattern inlibs/libm/libm/lib_scalbnl.c) for both little-endian and big-endian architectures.#else):PANIC()with an exact, IEEE-754 compliant mathematical fallback:-0.0/+0.0), infinities, and NaNs without crashing the kernel.<assert.h>include.<endian.h>in alphabetical order.Impact
trunclmath library support).truncl()on 128-bitlong doubleplatforms (e.g. RISC-V 64) will now execute properly instead of crashing with a kernel panic.libm.Testing
(-1, 1), signed zeros±0.0, infinities±Inf, andNaN.