summaryrefslogtreecommitdiffstats
path: root/tests/ui/numbers-arithmetic/float-nan.rs
blob: 0cc6473e5c48c440d813c2db388dc5787617145e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// run-pass

pub fn main() {
  let nan: f64 = f64::NAN;
  assert!((nan).is_nan());

  let inf: f64 = f64::INFINITY;
  let neg_inf: f64 = -f64::INFINITY;
  assert_eq!(-inf, neg_inf);

  assert!( nan !=  nan);
  assert!( nan != -nan);
  assert!(-nan != -nan);
  assert!(-nan !=  nan);

  assert!( nan !=   1.);
  assert!( nan !=   0.);
  assert!( nan !=  inf);
  assert!( nan != -inf);

  assert!(  1. !=  nan);
  assert!(  0. !=  nan);
  assert!( inf !=  nan);
  assert!(-inf !=  nan);

  assert!(!( nan == nan));
  assert!(!( nan == -nan));
  assert!(!( nan == 1.));
  assert!(!( nan == 0.));
  assert!(!( nan == inf));
  assert!(!( nan == -inf));
  assert!(!(  1. == nan));
  assert!(!(  0. == nan));
  assert!(!( inf == nan));
  assert!(!(-inf == nan));
  assert!(!(-nan == nan));
  assert!(!(-nan == -nan));

  assert!(!( nan >  nan));
  assert!(!( nan > -nan));
  assert!(!( nan >   0.));
  assert!(!( nan >  inf));
  assert!(!( nan > -inf));
  assert!(!(  0. >  nan));
  assert!(!( inf >  nan));
  assert!(!(-inf >  nan));
  assert!(!(-nan >  nan));

  assert!(!(nan <   0.));
  assert!(!(nan <   1.));
  assert!(!(nan <  -1.));
  assert!(!(nan <  inf));
  assert!(!(nan < -inf));
  assert!(!(nan <  nan));
  assert!(!(nan < -nan));

  assert!(!(  0. < nan));
  assert!(!(  1. < nan));
  assert!(!( -1. < nan));
  assert!(!( inf < nan));
  assert!(!(-inf < nan));
  assert!(!(-nan < nan));

  assert!((nan + inf).is_nan());
  assert!((nan + -inf).is_nan());
  assert!((nan + 0.).is_nan());
  assert!((nan + 1.).is_nan());
  assert!((nan * 1.).is_nan());
  assert!((nan / 1.).is_nan());
  assert!((nan / 0.).is_nan());
  assert!((0.0/0.0f64).is_nan());
  assert!((-inf + inf).is_nan());
  assert!((inf - inf).is_nan());

  assert!(!(-1.0f64).is_nan());
  assert!(!(0.0f64).is_nan());
  assert!(!(0.1f64).is_nan());
  assert!(!(1.0f64).is_nan());
  assert!(!(inf).is_nan());
  assert!(!(-inf).is_nan());
  assert!(!(1./-inf).is_nan());
}