Skip to content

Commit ffe7f0d

Browse files
authored
Merge pull request rust-lang#493 from tgross35/fma-sign
fma: Ensure zero has the correct sign
2 parents 9612576 + 4155869 commit ffe7f0d

File tree

3 files changed

+4
-47
lines changed

3 files changed

+4
-47
lines changed

crates/libm-test/src/precision.rs

+2-45
Original file line numberDiff line numberDiff line change
@@ -558,48 +558,5 @@ impl MaybeOverride<(f64, i32)> for SpecialCase {}
558558
#[cfg(f128_enabled)]
559559
impl MaybeOverride<(f128, i32)> for SpecialCase {}
560560

561-
impl MaybeOverride<(f32, f32, f32)> for SpecialCase {
562-
fn check_float<F: Float>(
563-
input: (f32, f32, f32),
564-
actual: F,
565-
expected: F,
566-
ctx: &CheckCtx,
567-
) -> CheckAction {
568-
ternop_common(input, actual, expected, ctx)
569-
}
570-
}
571-
impl MaybeOverride<(f64, f64, f64)> for SpecialCase {
572-
fn check_float<F: Float>(
573-
input: (f64, f64, f64),
574-
actual: F,
575-
expected: F,
576-
ctx: &CheckCtx,
577-
) -> CheckAction {
578-
ternop_common(input, actual, expected, ctx)
579-
}
580-
}
581-
582-
// F1 and F2 are always the same type, this is just to please generics
583-
fn ternop_common<F1: Float, F2: Float>(
584-
input: (F1, F1, F1),
585-
actual: F2,
586-
expected: F2,
587-
ctx: &CheckCtx,
588-
) -> CheckAction {
589-
// FIXME(fma): 754-2020 says "When the exact result of (a × b) + c is non-zero yet the result
590-
// of fusedMultiplyAdd is zero because of rounding, the zero result takes the sign of the
591-
// exact result". Our implementation returns the wrong sign:
592-
// fma(5e-324, -5e-324, 0.0) = 0.0 (should be -0.0)
593-
if ctx.base_name == BaseName::Fma
594-
&& (input.0.is_sign_negative() ^ input.1.is_sign_negative())
595-
&& input.0 != F1::ZERO
596-
&& input.1 != F1::ZERO
597-
&& input.2.biteq(F1::ZERO)
598-
&& expected.biteq(F2::NEG_ZERO)
599-
&& actual.biteq(F2::ZERO)
600-
{
601-
return XFAIL("fma sign");
602-
}
603-
604-
DEFAULT
605-
}
561+
impl MaybeOverride<(f32, f32, f32)> for SpecialCase {}
562+
impl MaybeOverride<(f64, f64, f64)> for SpecialCase {}

crates/musl-math-sys/musl

Submodule musl updated from 0784374 to 61399d4

src/math/generic/fma.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ where
3131
if nz.e >= ZEROINFNAN {
3232
if nz.e > ZEROINFNAN {
3333
/* z==0 */
34-
return x * y + z;
34+
return x * y;
3535
}
3636
return z;
3737
}

0 commit comments

Comments
 (0)