Skip to content

Some num tests fail for {i586, i686, x86_64}-unknown-linux-gnu #46948

Closed
@malbarbo

Description

@malbarbo

Consider the following tests extract from libstd:

#[cfg(test)]
mod tests {
    use std::f32;
    use std::f64;

    macro_rules! assert_approx_eq {
        ($a:expr, $b:expr) => ({
            let (a, b) = (&$a, &$b);
            assert!((*a - *b).abs() < 1.0e-6,
                    "{} is not approximately equal to {}", *a, *b);
        })
    }

    #[test]
    fn test_mul_add() {
        let nan = f64::NAN;
        let inf = f64::INFINITY;
        let neg_inf = f64::NEG_INFINITY;
        assert_approx_eq!(12.3f64.mul_add(4.5, 6.7), 62.05);
        assert_approx_eq!((-12.3f64).mul_add(-4.5, -6.7), 48.65);
        assert_approx_eq!(0.0f64.mul_add(8.9, 1.2), 1.2);
        assert_approx_eq!(3.4f64.mul_add(-0.0, 5.6), 5.6);
        assert!(nan.mul_add(7.8, 9.0).is_nan());
        assert_eq!(inf.mul_add(7.8, 9.0), inf);
        assert_eq!(neg_inf.mul_add(7.8, 9.0), neg_inf);
        assert_eq!(8.9f64.mul_add(inf, 3.2), inf);
        assert_eq!((-3.2f64).mul_add(2.4, neg_inf), neg_inf);
    }

    #[test]
    fn f32_test_float_bits_conv() {
        assert_eq!((1f32).to_bits(), 0x3f800000);
        assert_eq!((12.5f32).to_bits(), 0x41480000);
        assert_eq!((1337f32).to_bits(), 0x44a72000);
        assert_eq!((-14.25f32).to_bits(), 0xc1640000);
        assert_approx_eq!(f32::from_bits(0x3f800000), 1.0);
        assert_approx_eq!(f32::from_bits(0x41480000), 12.5);
        assert_approx_eq!(f32::from_bits(0x44a72000), 1337.0);
        assert_approx_eq!(f32::from_bits(0xc1640000), -14.25);

        // Check that NaNs roundtrip their bits regardless of signalingness
        // 0xA is 0b1010; 0x5 is 0b0101 -- so these two together clobbers all the mantissa bits
        let masked_nan1 = f32::NAN.to_bits() ^ 0x002A_AAAA;
        let masked_nan2 = f32::NAN.to_bits() ^ 0x0055_5555;
        assert!(f32::from_bits(masked_nan1).is_nan());
        assert!(f32::from_bits(masked_nan2).is_nan());

        assert_eq!(f32::from_bits(masked_nan1).to_bits(), masked_nan1);
        assert_eq!(f32::from_bits(masked_nan2).to_bits(), masked_nan2);
    }

    #[test]
    fn f64_test_float_bits_conv() {
        assert_eq!((1f64).to_bits(), 0x3ff0000000000000);
        assert_eq!((12.5f64).to_bits(), 0x4029000000000000);
        assert_eq!((1337f64).to_bits(), 0x4094e40000000000);
        assert_eq!((-14.25f64).to_bits(), 0xc02c800000000000);
        assert_approx_eq!(f64::from_bits(0x3ff0000000000000), 1.0);
        assert_approx_eq!(f64::from_bits(0x4029000000000000), 12.5);
        assert_approx_eq!(f64::from_bits(0x4094e40000000000), 1337.0);
        assert_approx_eq!(f64::from_bits(0xc02c800000000000), -14.25);

        // Check that NaNs roundtrip their bits regardless of signalingness
        // 0xA is 0b1010; 0x5 is 0b0101 -- so these two together clobbers all the mantissa bits
        let masked_nan1 = f64::NAN.to_bits() ^ 0x000A_AAAA_AAAA_AAAA;
        let masked_nan2 = f64::NAN.to_bits() ^ 0x0005_5555_5555_5555;
        assert!(f64::from_bits(masked_nan1).is_nan());
        assert!(f64::from_bits(masked_nan2).is_nan());

        assert_eq!(f64::from_bits(masked_nan1).to_bits(), masked_nan1);
        assert_eq!(f64::from_bits(masked_nan2).to_bits(), masked_nan2);
    }
}

Using rustc 1.24.0-nightly (250b49205 2017-12-21) it fails in debug mode for the targets {i586, i686}-unknown-linux-gnu but works in release mode. It works in both release and debug mode for x86_64-unknown-linux-gnu.

Using rustc 1.23.0-beta.2 (c9107ee93 2017-12-08) or rustc 1.22.1 (05e2e1c41 2017-11-22) only tests::test_mul_add works in release mode for {i586, i686, x86_64}-unknown-linux-gnu. For debug mode all tests fails for {i586, i686}-unknown-linux-gnu, tests::test_mul_add works for x86_64-unknown-linux-gnu.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-testsuiteArea: The testsuite used to check the correctness of rustcC-bugCategory: This is a bug.O-x86_32Target: x86 processors, 32 bit (like i686-*) (IA-32)T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions