about summary refs log tree commit diff
path: root/src/test/stdtest/float.rs
blob: 36f5dc167b1e09b747eacd9b8b4f2be1ad11469b (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
83
84
85
import core::*;

use std;
import float;

#[test]
fn test_from_str() {
   assert ( float::from_str("3") == 3. );
   assert ( float::from_str("  3  ") == 3. );
   assert ( float::from_str("3.14") == 3.14 );
   assert ( float::from_str("+3.14") == 3.14 );
   assert ( float::from_str("-3.14") == -3.14 );
   assert ( float::from_str("2.5E10") == 25000000000. );
   assert ( float::from_str("2.5e10") == 25000000000. );
   assert ( float::from_str("25000000000.E-10") == 2.5 );
   assert ( float::from_str("") == 0. );
   assert ( float::from_str(".") == 0. );
   assert ( float::from_str(".e1") == 0. );
   assert ( float::from_str(".e-1") == 0. );
   assert ( float::from_str("5.") == 5. );
   assert ( float::from_str(".5") == 0.5 );
   assert ( float::from_str("0.5") == 0.5 );
   assert ( float::from_str("0.5 ") == 0.5 );
   assert ( float::from_str(" 0.5 ") == 0.5 );
   assert ( float::from_str(" -.5 ") == -0.5 );
   assert ( float::from_str(" -.5 ") == -0.5 );
   assert ( float::from_str(" -5 ") == -5. );

   assert ( float::isNaN(float::from_str("x")) );
   assert ( float::from_str(" ") == 0. );
   assert ( float::from_str("   ") == 0. );
   assert ( float::from_str(" 0.5") == 0.5 );
   assert ( float::from_str(" 0.5 ") == 0.5 );
   assert ( float::from_str(" .1 ") == 0.1 );
   assert ( float::isNaN(float::from_str("e")) );
   assert ( float::isNaN(float::from_str("E")) );
   assert ( float::isNaN(float::from_str("E1")) );
   assert ( float::isNaN(float::from_str("1e1e1")) );
   assert ( float::isNaN(float::from_str("1e1.1")) );
   assert ( float::isNaN(float::from_str("1e1-1")) );
}

#[test]
fn test_positive() {
  assert(float::positive(float::infinity));
  assert(float::positive(1.));
  assert(float::positive(0.));
  assert(!float::positive(-1.));
  assert(!float::positive(float::neg_infinity));
  assert(!float::positive(1./float::neg_infinity));
  assert(!float::positive(float::NaN));
}

#[test]
fn test_negative() {
  assert(!float::negative(float::infinity));
  assert(!float::negative(1.));
  assert(!float::negative(0.));
  assert(float::negative(-1.));
  assert(float::negative(float::neg_infinity));
  assert(float::negative(1./float::neg_infinity));
  assert(!float::negative(float::NaN));
}

#[test]
fn test_nonpositive() {
  assert(!float::nonpositive(float::infinity));
  assert(!float::nonpositive(1.));
  assert(!float::nonpositive(0.));
  assert(float::nonpositive(-1.));
  assert(float::nonpositive(float::neg_infinity));
  assert(float::nonpositive(1./float::neg_infinity));
  assert(!float::nonpositive(float::NaN));
}

#[test]
fn test_nonnegative() {
  assert(float::nonnegative(float::infinity));
  assert(float::nonnegative(1.));
  assert(float::nonnegative(0.));
  assert(!float::nonnegative(-1.));
  assert(!float::nonnegative(float::neg_infinity));
  assert(!float::nonnegative(1./float::neg_infinity));
  assert(!float::nonnegative(float::NaN));
}