|
1 | 1 | use core::num::dec2flt::float::RawFloat;
|
2 | 2 |
|
| 3 | +// FIXME(f16_f128): enable on all targets once possible. |
| 4 | +#[test] |
| 5 | +#[cfg(target_has_reliable_f16)] |
| 6 | +fn test_f16_integer_decode() { |
| 7 | + assert_eq!(3.14159265359f16.integer_decode(), (1608, -9, 1)); |
| 8 | + assert_eq!((-8573.5918555f16).integer_decode(), (1072, 3, -1)); |
| 9 | + assert_eq!(2f16.powf(14.0).integer_decode(), (1 << 10, 4, 1)); |
| 10 | + assert_eq!(0f16.integer_decode(), (0, -25, 1)); |
| 11 | + assert_eq!((-0f16).integer_decode(), (0, -25, -1)); |
| 12 | + assert_eq!(f16::INFINITY.integer_decode(), (1 << 10, 6, 1)); |
| 13 | + assert_eq!(f16::NEG_INFINITY.integer_decode(), (1 << 10, 6, -1)); |
| 14 | + |
| 15 | + // Ignore the "sign" (quiet / signalling flag) of NAN. |
| 16 | + // It can vary between runtime operations and LLVM folding. |
| 17 | + let (nan_m, nan_p, _nan_s) = f16::NAN.integer_decode(); |
| 18 | + assert_eq!((nan_m, nan_p), (1536, 6)); |
| 19 | +} |
| 20 | + |
3 | 21 | #[test]
|
4 | 22 | fn test_f32_integer_decode() {
|
5 | 23 | assert_eq!(3.14159265359f32.integer_decode(), (13176795, -22, 1));
|
@@ -34,6 +52,27 @@ fn test_f64_integer_decode() {
|
34 | 52 |
|
35 | 53 | /* Sanity checks of computed magic numbers */
|
36 | 54 |
|
| 55 | +// FIXME(f16_f128): enable on all targets once possible. |
| 56 | +#[test] |
| 57 | +#[cfg(target_has_reliable_f16)] |
| 58 | +fn test_f16_consts() { |
| 59 | + assert_eq!(<f16 as RawFloat>::INFINITY, f16::INFINITY); |
| 60 | + assert_eq!(<f16 as RawFloat>::NEG_INFINITY, -f16::INFINITY); |
| 61 | + assert_eq!(<f16 as RawFloat>::NAN.to_bits(), f16::NAN.to_bits()); |
| 62 | + assert_eq!(<f16 as RawFloat>::NEG_NAN.to_bits(), (-f16::NAN).to_bits()); |
| 63 | + assert_eq!(<f16 as RawFloat>::SIG_BITS, 10); |
| 64 | + assert_eq!(<f16 as RawFloat>::MIN_EXPONENT_ROUND_TO_EVEN, -22); |
| 65 | + assert_eq!(<f16 as RawFloat>::MAX_EXPONENT_ROUND_TO_EVEN, 5); |
| 66 | + assert_eq!(<f16 as RawFloat>::MIN_EXPONENT_FAST_PATH, -4); |
| 67 | + assert_eq!(<f16 as RawFloat>::MAX_EXPONENT_FAST_PATH, 4); |
| 68 | + assert_eq!(<f16 as RawFloat>::MAX_EXPONENT_DISGUISED_FAST_PATH, 7); |
| 69 | + assert_eq!(<f16 as RawFloat>::EXP_MIN, -14); |
| 70 | + assert_eq!(<f16 as RawFloat>::EXP_SAT, 0x1f); |
| 71 | + assert_eq!(<f16 as RawFloat>::SMALLEST_POWER_OF_TEN, -27); |
| 72 | + assert_eq!(<f16 as RawFloat>::LARGEST_POWER_OF_TEN, 4); |
| 73 | + assert_eq!(<f16 as RawFloat>::MAX_MANTISSA_FAST_PATH, 2048); |
| 74 | +} |
| 75 | + |
37 | 76 | #[test]
|
38 | 77 | fn test_f32_consts() {
|
39 | 78 | assert_eq!(<f32 as RawFloat>::INFINITY, f32::INFINITY);
|
|
0 commit comments