about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTrevor Gross <tmgross@umich.edu>2025-02-05 20:32:11 -0600
committerGitHub <noreply@github.com>2025-02-05 20:32:11 -0600
commitf070e65e4fb922b039256c50d16459c22e6df3ba (patch)
treead48cca70513159eec482377965bfb0d83efce2d
parent3fbe59f8503fb5eb151bc995ba2c1ebad80dcbb5 (diff)
parentada2d9ae1d8747cd6159fc090c4fa39b0c74d3bd (diff)
downloadrust-f070e65e4fb922b039256c50d16459c22e6df3ba.tar.gz
rust-f070e65e4fb922b039256c50d16459c22e6df3ba.zip
Merge pull request rust-lang/libm#493 from tgross35/fma-sign
fma: Ensure zero has the correct sign
-rw-r--r--library/compiler-builtins/libm/crates/libm-test/src/precision.rs47
m---------library/compiler-builtins/libm/crates/musl-math-sys/musl0
-rw-r--r--library/compiler-builtins/libm/src/math/generic/fma.rs2
3 files changed, 3 insertions, 46 deletions
diff --git a/library/compiler-builtins/libm/crates/libm-test/src/precision.rs b/library/compiler-builtins/libm/crates/libm-test/src/precision.rs
index 051960b7a55..596f91fe1ef 100644
--- a/library/compiler-builtins/libm/crates/libm-test/src/precision.rs
+++ b/library/compiler-builtins/libm/crates/libm-test/src/precision.rs
@@ -558,48 +558,5 @@ impl MaybeOverride<(f64, i32)> for SpecialCase {}
 #[cfg(f128_enabled)]
 impl MaybeOverride<(f128, i32)> for SpecialCase {}
 
-impl MaybeOverride<(f32, f32, f32)> for SpecialCase {
-    fn check_float<F: Float>(
-        input: (f32, f32, f32),
-        actual: F,
-        expected: F,
-        ctx: &CheckCtx,
-    ) -> CheckAction {
-        ternop_common(input, actual, expected, ctx)
-    }
-}
-impl MaybeOverride<(f64, f64, f64)> for SpecialCase {
-    fn check_float<F: Float>(
-        input: (f64, f64, f64),
-        actual: F,
-        expected: F,
-        ctx: &CheckCtx,
-    ) -> CheckAction {
-        ternop_common(input, actual, expected, ctx)
-    }
-}
-
-// F1 and F2 are always the same type, this is just to please generics
-fn ternop_common<F1: Float, F2: Float>(
-    input: (F1, F1, F1),
-    actual: F2,
-    expected: F2,
-    ctx: &CheckCtx,
-) -> CheckAction {
-    // FIXME(fma): 754-2020 says "When the exact result of (a × b) + c is non-zero yet the result
-    // of fusedMultiplyAdd is zero because of rounding, the zero result takes the sign of the
-    // exact result". Our implementation returns the wrong sign:
-    //     fma(5e-324, -5e-324, 0.0) = 0.0 (should be -0.0)
-    if ctx.base_name == BaseName::Fma
-        && (input.0.is_sign_negative() ^ input.1.is_sign_negative())
-        && input.0 != F1::ZERO
-        && input.1 != F1::ZERO
-        && input.2.biteq(F1::ZERO)
-        && expected.biteq(F2::NEG_ZERO)
-        && actual.biteq(F2::ZERO)
-    {
-        return XFAIL("fma sign");
-    }
-
-    DEFAULT
-}
+impl MaybeOverride<(f32, f32, f32)> for SpecialCase {}
+impl MaybeOverride<(f64, f64, f64)> for SpecialCase {}
diff --git a/library/compiler-builtins/libm/crates/musl-math-sys/musl b/library/compiler-builtins/libm/crates/musl-math-sys/musl
-Subproject 0784374d561435f7c787a555aeab8ede699ed29
+Subproject 61399d4bd02ae1ec03068445aa7ffe9174466bf
diff --git a/library/compiler-builtins/libm/src/math/generic/fma.rs b/library/compiler-builtins/libm/src/math/generic/fma.rs
index 3d5459f1a04..b0e2117ea09 100644
--- a/library/compiler-builtins/libm/src/math/generic/fma.rs
+++ b/library/compiler-builtins/libm/src/math/generic/fma.rs
@@ -31,7 +31,7 @@ where
     if nz.e >= ZEROINFNAN {
         if nz.e > ZEROINFNAN {
             /* z==0 */
-            return x * y + z;
+            return x * y;
         }
         return z;
     }