Commit | Line | Data |
925fa5a8 |
1 | #!./perl |
2 | |
20f6aaab |
3 | print "1..50\n"; |
925fa5a8 |
4 | |
5 | # First test whether the number stringification works okay. |
6 | # (Testing with == would exercize the IV/NV part, not the PV.) |
7 | |
8 | $a = 1; "$a"; |
bb7cd144 |
9 | print $a eq "1" ? "ok 1\n" : "not ok 1 # $a\n"; |
925fa5a8 |
10 | |
11 | $a = -1; "$a"; |
bb7cd144 |
12 | print $a eq "-1" ? "ok 2\n" : "not ok 2 # $a\n"; |
925fa5a8 |
13 | |
14 | $a = 1.; "$a"; |
bb7cd144 |
15 | print $a eq "1" ? "ok 3\n" : "not ok 3 # $a\n"; |
925fa5a8 |
16 | |
17 | $a = -1.; "$a"; |
bb7cd144 |
18 | print $a eq "-1" ? "ok 4\n" : "not ok 4 # $a\n"; |
925fa5a8 |
19 | |
20 | $a = 0.1; "$a"; |
bb7cd144 |
21 | print $a eq "0.1" ? "ok 5\n" : "not ok 5 # $a\n"; |
925fa5a8 |
22 | |
23 | $a = -0.1; "$a"; |
bb7cd144 |
24 | print $a eq "-0.1" ? "ok 6\n" : "not ok 6 # $a\n"; |
925fa5a8 |
25 | |
26 | $a = .1; "$a"; |
bb7cd144 |
27 | print $a eq "0.1" ? "ok 7\n" : "not ok 7 # $a\n"; |
925fa5a8 |
28 | |
29 | $a = -.1; "$a"; |
bb7cd144 |
30 | print $a eq "-0.1" ? "ok 8\n" : "not ok 8 # $a\n"; |
925fa5a8 |
31 | |
32 | $a = 10.01; "$a"; |
bb7cd144 |
33 | print $a eq "10.01" ? "ok 9\n" : "not ok 9 # $a\n"; |
925fa5a8 |
34 | |
35 | $a = 1e3; "$a"; |
bb7cd144 |
36 | print $a eq "1000" ? "ok 10\n" : "not ok 10 # $a\n"; |
925fa5a8 |
37 | |
38 | $a = 10.01e3; "$a"; |
bb7cd144 |
39 | print $a eq "10010" ? "ok 11\n" : "not ok 11 # $a\n"; |
925fa5a8 |
40 | |
41 | $a = 0b100; "$a"; |
bb7cd144 |
42 | print $a eq "4" ? "ok 12\n" : "not ok 12 # $a\n"; |
925fa5a8 |
43 | |
44 | $a = 0100; "$a"; |
bb7cd144 |
45 | print $a eq "64" ? "ok 13\n" : "not ok 13 # $a\n"; |
925fa5a8 |
46 | |
47 | $a = 0x100; "$a"; |
bb7cd144 |
48 | print $a eq "256" ? "ok 14\n" : "not ok 14 # $a\n"; |
925fa5a8 |
49 | |
50 | $a = 1000; "$a"; |
bb7cd144 |
51 | print $a eq "1000" ? "ok 15\n" : "not ok 15 # $a\n"; |
925fa5a8 |
52 | |
53 | # Okay, now test the numerics. |
54 | # We may be assuming too much, given the painfully well-known floating |
55 | # point sloppiness, but the following are still quite reasonable |
56 | # assumptions which if not working would confuse people quite badly. |
57 | |
58 | $a = 1; "$a"; # Keep the stringification as a potential troublemaker. |
bb7cd144 |
59 | print $a + 1 == 2 ? "ok 16\n" : "not ok 16 #" . $a + 1 . "\n"; |
60 | # Don't know how useful printing the stringification of $a + 1 really is. |
925fa5a8 |
61 | |
62 | $a = -1; "$a"; |
bb7cd144 |
63 | print $a + 1 == 0 ? "ok 17\n" : "not ok 17 #" . $a + 1 . "\n"; |
925fa5a8 |
64 | |
65 | $a = 1.; "$a"; |
bb7cd144 |
66 | print $a + 1 == 2 ? "ok 18\n" : "not ok 18 #" . $a + 1 . "\n"; |
925fa5a8 |
67 | |
68 | $a = -1.; "$a"; |
bb7cd144 |
69 | print $a + 1 == 0 ? "ok 19\n" : "not ok 19 #" . $a + 1 . "\n"; |
925fa5a8 |
70 | |
49424450 |
71 | sub ok { # Can't assume too much of floating point numbers. |
8194bf88 |
72 | my ($a, $b, $c) = @_; |
49424450 |
73 | abs($a - $b) <= $c; |
74 | } |
75 | |
925fa5a8 |
76 | $a = 0.1; "$a"; |
49424450 |
77 | print ok($a + 1, 1.1, 0.05) ? "ok 20\n" : "not ok 20 #" . $a + 1 . "\n"; |
925fa5a8 |
78 | |
79 | $a = -0.1; "$a"; |
49424450 |
80 | print ok($a + 1, 0.9, 0.05) ? "ok 21\n" : "not ok 21 #" . $a + 1 . "\n"; |
925fa5a8 |
81 | |
82 | $a = .1; "$a"; |
49424450 |
83 | print ok($a + 1, 1.1, 0.005) ? "ok 22\n" : "not ok 22 #" . $a + 1 . "\n"; |
925fa5a8 |
84 | |
85 | $a = -.1; "$a"; |
49424450 |
86 | print ok($a + 1, 0.9, 0.05) ? "ok 23\n" : "not ok 23 #" . $a + 1 . "\n"; |
925fa5a8 |
87 | |
88 | $a = 10.01; "$a"; |
49424450 |
89 | print ok($a + 1, 11.01, 0.005) ? "ok 24\n" : "not ok 24 #" . $a + 1 . "\n"; |
925fa5a8 |
90 | |
91 | $a = 1e3; "$a"; |
bb7cd144 |
92 | print $a + 1 == 1001 ? "ok 25\n" : "not ok 25 #" . $a + 1 . "\n"; |
925fa5a8 |
93 | |
94 | $a = 10.01e3; "$a"; |
bb7cd144 |
95 | print $a + 1 == 10011 ? "ok 26\n" : "not ok 26 #" . $a + 1 . "\n"; |
925fa5a8 |
96 | |
97 | $a = 0b100; "$a"; |
bb7cd144 |
98 | print $a + 1 == 0b101 ? "ok 27\n" : "not ok 27 #" . $a + 1 . "\n"; |
925fa5a8 |
99 | |
100 | $a = 0100; "$a"; |
bb7cd144 |
101 | print $a + 1 == 0101 ? "ok 28\n" : "not ok 28 #" . $a + 1 . "\n"; |
925fa5a8 |
102 | |
103 | $a = 0x100; "$a"; |
bb7cd144 |
104 | print $a + 1 == 0x101 ? "ok 29\n" : "not ok 29 #" . $a + 1 . "\n"; |
925fa5a8 |
105 | |
106 | $a = 1000; "$a"; |
bb7cd144 |
107 | print $a + 1 == 1001 ? "ok 30\n" : "not ok 30 #" . $a + 1 . "\n"; |
0ad373b6 |
108 | |
109 | # back to some basic stringify tests |
d1eb8299 |
110 | # we expect NV stringification to work according to C sprintf %.*g rules |
0ad373b6 |
111 | |
0443feb9 |
112 | if ($^O eq 'os2') { # In the long run, fix this. For 5.8.0, deal. |
113 | $a = 0.01; "$a"; |
114 | print $a eq "0.01" || $a eq '1e-02' ? "ok 31\n" : "not ok 31 # $a\n"; |
0ad373b6 |
115 | |
0443feb9 |
116 | $a = 0.001; "$a"; |
117 | print $a eq "0.001" || $a eq '1e-03' ? "ok 32\n" : "not ok 32 # $a\n"; |
0ad373b6 |
118 | |
0443feb9 |
119 | $a = 0.0001; "$a"; |
120 | print $a eq "0.0001" || $a eq '1e-04' ? "ok 33\n" : "not ok 33 # $a\n"; |
121 | } else { |
122 | $a = 0.01; "$a"; |
123 | print $a eq "0.01" ? "ok 31\n" : "not ok 31 # $a\n"; |
124 | |
125 | $a = 0.001; "$a"; |
126 | print $a eq "0.001" ? "ok 32\n" : "not ok 32 # $a\n"; |
127 | |
128 | $a = 0.0001; "$a"; |
129 | print $a eq "0.0001" ? "ok 33\n" : "not ok 33 # $a\n"; |
130 | } |
0ad373b6 |
131 | |
132 | $a = 0.00009; "$a"; |
133 | print $a eq "9e-05" || $a eq "9e-005" ? "ok 34\n" : "not ok 34 # $a\n"; |
134 | |
135 | $a = 1.1; "$a"; |
136 | print $a eq "1.1" ? "ok 35\n" : "not ok 35 # $a\n"; |
137 | |
138 | $a = 1.01; "$a"; |
139 | print $a eq "1.01" ? "ok 36\n" : "not ok 36 # $a\n"; |
140 | |
141 | $a = 1.001; "$a"; |
142 | print $a eq "1.001" ? "ok 37\n" : "not ok 37 # $a\n"; |
143 | |
144 | $a = 1.0001; "$a"; |
145 | print $a eq "1.0001" ? "ok 38\n" : "not ok 38 # $a\n"; |
146 | |
147 | $a = 1.00001; "$a"; |
148 | print $a eq "1.00001" ? "ok 39\n" : "not ok 39 # $a\n"; |
149 | |
150 | $a = 1.000001; "$a"; |
151 | print $a eq "1.000001" ? "ok 40\n" : "not ok 40 # $a\n"; |
152 | |
153 | $a = 0.; "$a"; |
154 | print $a eq "0" ? "ok 41\n" : "not ok 41 # $a\n"; |
155 | |
156 | $a = 100000.; "$a"; |
157 | print $a eq "100000" ? "ok 42\n" : "not ok 42 # $a\n"; |
158 | |
159 | $a = -100000.; "$a"; |
160 | print $a eq "-100000" ? "ok 43\n" : "not ok 43 # $a\n"; |
161 | |
162 | $a = 123.456; "$a"; |
163 | print $a eq "123.456" ? "ok 44\n" : "not ok 44 # $a\n"; |
164 | |
94b339ad |
165 | $a = 1e34; "$a"; |
1a6a79b7 |
166 | unless ($^O eq 'posix-bc') |
0d746ee5 |
167 | { print $a eq "1e+34" || $a eq "1e+034" ? "ok 45\n" : "not ok 45 # $a\n"; } |
1a6a79b7 |
168 | else |
169 | { print "ok 45 # skipped on $^O\n"; } |
8194bf88 |
170 | |
171 | # see bug #15073 |
172 | |
173 | $a = 0.00049999999999999999999999999999999999999; |
174 | $b = 0.0005000000000000000104; |
175 | print $a <= $b ? "ok 46\n" : "not ok 46\n"; |
176 | |
c3892a8e |
177 | if ($^O eq 'ultrix' || $^O eq 'VMS') { |
178 | # Ultrix enters looong nirvana over this. VMS blows up when configured with |
179 | # D_FLOAT (but with G_FLOAT or IEEE works fine). The test should probably |
180 | # make the number of 0's a function of NV_DIG, but that's not in Config and |
181 | # we probably don't want to suck Config into a base test anyway. |
ad415dae |
182 | print "ok 47\n"; |
183 | } else { |
184 | $a = 0.00000000000000000000000000000000000000000000000000000000000000000001; |
185 | print $a > 0 ? "ok 47\n" : "not ok 47\n"; |
186 | } |
8194bf88 |
187 | |
188 | $a = 80000.0000000000000000000000000; |
189 | print $a == 80000.0 ? "ok 48\n" : "not ok 48\n"; |
190 | |
191 | $a = 1.0000000000000000000000000000000000000000000000000000000000000000000e1; |
192 | print $a == 10.0 ? "ok 49\n" : "not ok 49\n"; |
20f6aaab |
193 | |
194 | # From Math/Trig - number has to be long enough to exceed at least DBL_DIG |
195 | |
196 | $a = 57.295779513082320876798154814169; |
197 | print ok($a*10,572.95779513082320876798154814169,1e-10) ? "ok 50\n" : |
198 | "not ok 50 # $a\n"; |