|
1 | 1 | //! Tests added to `rustc_apfloat`, that were not ported from the C++ code.
|
2 | 2 |
|
3 |
| -use rustc_apfloat::ieee::{Double, Single}; |
| 3 | +use rustc_apfloat::ieee::{Double, Single, X87DoubleExtended}; |
4 | 4 | use rustc_apfloat::Float;
|
5 | 5 |
|
6 | 6 | // `f32 -> i128 -> f32` previously-crashing bit-patterns (found by fuzzing).
|
@@ -385,3 +385,29 @@ fn fuzz_fma_with_expected_outputs() {
|
385 | 385 | assert_eq!(a.mul_add(b, c).value.to_bits(), expected_bits.into());
|
386 | 386 | }
|
387 | 387 | }
|
| 388 | + |
| 389 | +// x87 80-bit "extended precision"/`long double` bit-patterns which used to |
| 390 | +// produce the wrong output when negated (found by fuzzing - though fuzzing also |
| 391 | +// found many examples in all ops, as the root issue was the handling of the |
| 392 | +// bit-level encoding itself, but negation was the easiest op to test here). |
| 393 | +pub const FUZZ_X87_F80_NEG_CASES_WITH_EXPECTED_OUTPUTS: &[(u128, u128)] = &[ |
| 394 | + ( |
| 395 | + 0x01010101010100000000, /* 3.05337213397376214408E-4857 */ |
| 396 | + 0x81010101010100000000, /* -3.05337213397376214408E-4857 */ |
| 397 | + ), |
| 398 | + ( |
| 399 | + 0x0000ff7f2300ff000000, /* 6.71098449692300485303E-4932 */ |
| 400 | + 0x8001ff7f2300ff000000, /* -6.71098449692300485303E-4932 */ |
| 401 | + ), |
| 402 | + ( |
| 403 | + 0x00008000000000000000, /* 3.36210314311209350626E-4932 */ |
| 404 | + 0x80018000000000000000, /* -3.36210314311209350626E-4932 */ |
| 405 | + ), |
| 406 | +]; |
| 407 | + |
| 408 | +#[test] |
| 409 | +fn fuzz_x87_f80_neg_with_expected_outputs() { |
| 410 | + for &(bits, expected_bits) in FUZZ_X87_F80_NEG_CASES_WITH_EXPECTED_OUTPUTS { |
| 411 | + assert_eq!((-X87DoubleExtended::from_bits(bits)).to_bits(), expected_bits); |
| 412 | + } |
| 413 | +} |
0 commit comments