Auto merge of #127013 - tgross35:f16-format-parse, r=Mark-Simulacrum · rust-lang/rust@4d051fb (original) (raw)

1

1

`use core::num::dec2flt:🛟: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

`+

#[cfg(not(miri))] // miri doesn't have powf16

`

``

10

`+

assert_eq!(2f16.powf(14.0).integer_decode(), (1 << 10, 4, 1));

`

``

11

`+

assert_eq!(0f16.integer_decode(), (0, -25, 1));

`

``

12

`+

assert_eq!((-0f16).integer_decode(), (0, -25, -1));

`

``

13

`+

assert_eq!(f16::INFINITY.integer_decode(), (1 << 10, 6, 1));

`

``

14

`+

assert_eq!(f16::NEG_INFINITY.integer_decode(), (1 << 10, 6, -1));

`

``

15

+

``

16

`+

// Ignore the "sign" (quiet / signalling flag) of NAN.

`

``

17

`+

// It can vary between runtime operations and LLVM folding.

`

``

18

`+

let (nan_m, nan_p, _nan_s) = f16::NAN.integer_decode();

`

``

19

`+

assert_eq!((nan_m, nan_p), (1536, 6));

`

``

20

`+

}

`

``

21

+

3

22

`#[test]

`

4

23

`fn test_f32_integer_decode() {

`

5

24

`assert_eq!(3.14159265359f32.integer_decode(), (13176795, -22, 1));

`

`@@ -34,6 +53,27 @@ fn test_f64_integer_decode() {

`

34

53

``

35

54

`/* Sanity checks of computed magic numbers */

`

36

55

``

``

56

`+

// FIXME(f16_f128): enable on all targets once possible.

`

``

57

`+

#[test]

`

``

58

`+

#[cfg(target_has_reliable_f16)]

`

``

59

`+

fn test_f16_consts() {

`

``

60

`+

assert_eq!(::INFINITY, f16::INFINITY);

`

``

61

`+

assert_eq!(::NEG_INFINITY, -f16::INFINITY);

`

``

62

`+

assert_eq!(::NAN.to_bits(), f16::NAN.to_bits());

`

``

63

`+

assert_eq!(::NEG_NAN.to_bits(), (-f16::NAN).to_bits());

`

``

64

`+

assert_eq!(::SIG_BITS, 10);

`

``

65

`+

assert_eq!(::MIN_EXPONENT_ROUND_TO_EVEN, -22);

`

``

66

`+

assert_eq!(::MAX_EXPONENT_ROUND_TO_EVEN, 5);

`

``

67

`+

assert_eq!(::MIN_EXPONENT_FAST_PATH, -4);

`

``

68

`+

assert_eq!(::MAX_EXPONENT_FAST_PATH, 4);

`

``

69

`+

assert_eq!(::MAX_EXPONENT_DISGUISED_FAST_PATH, 7);

`

``

70

`+

assert_eq!(::EXP_MIN, -14);

`

``

71

`+

assert_eq!(::EXP_SAT, 0x1f);

`

``

72

`+

assert_eq!(::SMALLEST_POWER_OF_TEN, -27);

`

``

73

`+

assert_eq!(::LARGEST_POWER_OF_TEN, 4);

`

``

74

`+

assert_eq!(::MAX_MANTISSA_FAST_PATH, 2048);

`

``

75

`+

}

`

``

76

+

37

77

`#[test]

`

38

78

`fn test_f32_consts() {

`

39

79

`assert_eq!(::INFINITY, f32::INFINITY);

`