allow /0|NaN/ on some bigfloatpm.t tests for portability; other
[p5sagit/p5-mst-13.2.git] / t / lib / bigfloatpm.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6 }
7
8 use Math::BigFloat;
9
10 $test = 0;
11 $| = 1;
12 print "1..358\n";
13 while (<DATA>) {
14        chop;
15        if (s/^&//) {
16                $f = $_;
17         } elsif (/^\$.*/) {
18                 eval "$_;";
19        } else {
20                ++$test;
21                @args = split(/:/,$_,99);
22                $ans = pop(@args);
23                $try = "\$x = new Math::BigFloat \"$args[0]\";";
24                if ($f eq "fnorm"){
25                    $try .= "\$x+0;";
26                } elsif ($f eq "fneg") {
27                    $try .= "-\$x;";
28                } elsif ($f eq "fabs") {
29                    $try .= "abs \$x;";
30                } elsif ($f eq "fround") {
31                    $try .= "0+\$x->fround($args[1]);";
32                } elsif ($f eq "ffround") {
33                    $try .= "0+\$x->ffround($args[1]);";
34                } elsif ($f eq "fsqrt") {
35                    $try .= "0+\$x->fsqrt;";
36                } else {
37                    $try .= "\$y = new Math::BigFloat \"$args[1]\";";
38                    if ($f eq fcmp){
39                        $try .= "\$x <=> \$y;";
40                    }elsif ($f eq fadd){
41                        $try .= "\$x + \$y;";
42                    }elsif ($f eq fsub){
43                        $try .= "\$x - \$y;";
44                    }elsif ($f eq fmul){
45                        $try .= "\$x * \$y;";
46                    }elsif ($f eq fdiv){
47                        $try .= "\$x / \$y;";
48                    } else { warn "Unknown op"; }
49                }
50                #print ">>>",$try,"<<<\n";
51                $ans1 = eval $try;
52                if ($ans =~ m|^/(.*)$|) {
53                    my $pat = $1;
54                    if ($ans1 =~ /$pat/) {
55                        print "ok $test\n";
56                    }
57                    else {
58                        print "not ok $test\n";
59                        print "# '$try' expected: /$pat/ got: '$ans1'\n";
60                    }
61                }
62                elsif ("$ans1" eq $ans) { #bug!
63                        print "ok $test\n";
64                } else {
65                        print "not ok $test\n";
66                        print "# '$try' expected: '$ans' got: '$ans1'\n";
67                }
68        }
69
70 __END__
71 &fnorm
72 abc:
73    1 a:
74 1bcd2:
75 11111b:
76 +1z:
77 -1z:
78 0:0.
79 +0:0.
80 +00:0.
81 +0 0 0:0.
82 000000  0000000   00000:0.
83 -0:0.
84 -0000:0.
85 +1:1.
86 +01:1.
87 +001:1.
88 +00000100000:100000.
89 123456789:123456789.
90 -1:-1.
91 -01:-1.
92 -001:-1.
93 -123456789:-123456789.
94 -00000100000:-100000.
95 123.456a:
96 123.456:123.456
97 0.01:.01
98 .002:.002
99 -0.0003:-.0003
100 -.0000000004:-.0000000004
101 123456E2:12345600.
102 123456E-2:1234.56
103 -123456E2:-12345600.
104 -123456E-2:-1234.56
105 1e1:10.
106 2e-11:.00000000002
107 -3e111:-3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.
108 -4e-1111:-.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004
109 &fneg
110 abd:
111 +0:0.
112 +1:-1.
113 -1:1.
114 +123456789:-123456789.
115 -123456789:123456789.
116 +123.456789:-123.456789
117 -123456.789:123456.789
118 &fabs
119 abc:
120 +0:0.
121 +1:1.
122 -1:1.
123 +123456789:123456789.
124 -123456789:123456789.
125 +123.456789:123.456789
126 -123456.789:123456.789
127 &fround
128 $Math::BigFloat::rnd_mode = 'trunc'
129 +10123456789:5:10123000000
130 -10123456789:5:-10123000000
131 +10123456789:9:10123456700
132 -10123456789:9:-10123456700
133 +101234500:6:101234000
134 -101234500:6:-101234000
135 $Math::BigFloat::rnd_mode = 'zero'
136 +20123456789:5:20123000000
137 -20123456789:5:-20123000000
138 +20123456789:9:20123456800
139 -20123456789:9:-20123456800
140 +201234500:6:201234000
141 -201234500:6:-201234000
142 $Math::BigFloat::rnd_mode = '+inf'
143 +30123456789:5:30123000000
144 -30123456789:5:-30123000000
145 +30123456789:9:30123456800
146 -30123456789:9:-30123456800
147 +301234500:6:301235000
148 -301234500:6:-301234000
149 $Math::BigFloat::rnd_mode = '-inf'
150 +40123456789:5:40123000000
151 -40123456789:5:-40123000000
152 +40123456789:9:40123456800
153 -40123456789:9:-40123456800
154 +401234500:6:401234000
155 -401234500:6:-401235000
156 $Math::BigFloat::rnd_mode = 'odd'
157 +50123456789:5:50123000000
158 -50123456789:5:-50123000000
159 +50123456789:9:50123456800
160 -50123456789:9:-50123456800
161 +501234500:6:501235000
162 -501234500:6:-501235000
163 $Math::BigFloat::rnd_mode = 'even'
164 +60123456789:5:60123000000
165 -60123456789:5:-60123000000
166 +60123456789:9:60123456800
167 -60123456789:9:-60123456800
168 +601234500:6:601234000
169 -601234500:6:-601234000
170 &ffround
171 $Math::BigFloat::rnd_mode = 'trunc'
172 +1.23:-1:1.2
173 -1.23:-1:-1.2
174 +1.27:-1:1.2
175 -1.27:-1:-1.2
176 +1.25:-1:1.2
177 -1.25:-1:-1.2
178 +1.35:-1:1.3
179 -1.35:-1:-1.3
180 -0.006:-1:0
181 -0.006:-2:0
182 -0.0065:-3:-0.006
183 -0.0065:-4:-0.0065
184 -0.0065:-5:-0.0065
185 $Math::BigFloat::rnd_mode = 'zero'
186 +2.23:-1:2.2
187 -2.23:-1:-2.2
188 +2.27:-1:2.3
189 -2.27:-1:-2.3
190 +2.25:-1:2.2
191 -2.25:-1:-2.2
192 +2.35:-1:2.3
193 -2.35:-1:-2.3
194 -0.0065:-1:0
195 -0.0065:-2:-0.01
196 -0.0065:-3:-0.006
197 -0.0065:-4:-0.0065
198 -0.0065:-5:-0.0065
199 $Math::BigFloat::rnd_mode = '+inf'
200 +3.23:-1:3.2
201 -3.23:-1:-3.2
202 +3.27:-1:3.3
203 -3.27:-1:-3.3
204 +3.25:-1:3.3
205 -3.25:-1:-3.2
206 +3.35:-1:3.4
207 -3.35:-1:-3.3
208 -0.0065:-1:0
209 -0.0065:-2:-0.01
210 -0.0065:-3:-0.006
211 -0.0065:-4:-0.0065
212 -0.0065:-5:-0.0065
213 $Math::BigFloat::rnd_mode = '-inf'
214 +4.23:-1:4.2
215 -4.23:-1:-4.2
216 +4.27:-1:4.3
217 -4.27:-1:-4.3
218 +4.25:-1:4.2
219 -4.25:-1:-4.3
220 +4.35:-1:4.3
221 -4.35:-1:-4.4
222 -0.0065:-1:0
223 -0.0065:-2:-0.01
224 -0.0065:-3:-0.007
225 -0.0065:-4:-0.0065
226 -0.0065:-5:-0.0065
227 $Math::BigFloat::rnd_mode = 'odd'
228 +5.23:-1:5.2
229 -5.23:-1:-5.2
230 +5.27:-1:5.3
231 -5.27:-1:-5.3
232 +5.25:-1:5.3
233 -5.25:-1:-5.3
234 +5.35:-1:5.3
235 -5.35:-1:-5.3
236 -0.0065:-1:0
237 -0.0065:-2:-0.01
238 -0.0065:-3:-0.007
239 -0.0065:-4:-0.0065
240 -0.0065:-5:-0.0065
241 $Math::BigFloat::rnd_mode = 'even'
242 +6.23:-1:6.2
243 -6.23:-1:-6.2
244 +6.27:-1:6.3
245 -6.27:-1:-6.3
246 +6.25:-1:6.2
247 -6.25:-1:-6.2
248 +6.35:-1:6.4
249 -6.35:-1:-6.4
250 -0.0065:-1:0
251 -0.0065:-2:-0.01
252 -0.0065:-3:-0.006
253 -0.0065:-4:-0.0065
254 -0.0065:-5:-0.0065
255 &fcmp
256 abc:abc:
257 abc:+0:
258 +0:abc:
259 +0:+0:0
260 -1:+0:-1
261 +0:-1:1
262 +1:+0:1
263 +0:+1:-1
264 -1:+1:-1
265 +1:-1:1
266 -1:-1:0
267 +1:+1:0
268 +123:+123:0
269 +123:+12:1
270 +12:+123:-1
271 -123:-123:0
272 -123:-12:-1
273 -12:-123:1
274 +123:+124:-1
275 +124:+123:1
276 -123:-124:1
277 -124:-123:-1
278 &fadd
279 abc:abc:
280 abc:+0:
281 +0:abc:
282 +0:+0:0.
283 +1:+0:1.
284 +0:+1:1.
285 +1:+1:2.
286 -1:+0:-1.
287 +0:-1:-1.
288 -1:-1:-2.
289 -1:+1:0.
290 +1:-1:0.
291 +9:+1:10.
292 +99:+1:100.
293 +999:+1:1000.
294 +9999:+1:10000.
295 +99999:+1:100000.
296 +999999:+1:1000000.
297 +9999999:+1:10000000.
298 +99999999:+1:100000000.
299 +999999999:+1:1000000000.
300 +9999999999:+1:10000000000.
301 +99999999999:+1:100000000000.
302 +10:-1:9.
303 +100:-1:99.
304 +1000:-1:999.
305 +10000:-1:9999.
306 +100000:-1:99999.
307 +1000000:-1:999999.
308 +10000000:-1:9999999.
309 +100000000:-1:99999999.
310 +1000000000:-1:999999999.
311 +10000000000:-1:9999999999.
312 +123456789:+987654321:1111111110.
313 -123456789:+987654321:864197532.
314 -123456789:-987654321:-1111111110.
315 +123456789:-987654321:-864197532.
316 &fsub
317 abc:abc:
318 abc:+0:
319 +0:abc:
320 +0:+0:0.
321 +1:+0:1.
322 +0:+1:-1.
323 +1:+1:0.
324 -1:+0:-1.
325 +0:-1:1.
326 -1:-1:0.
327 -1:+1:-2.
328 +1:-1:2.
329 +9:+1:8.
330 +99:+1:98.
331 +999:+1:998.
332 +9999:+1:9998.
333 +99999:+1:99998.
334 +999999:+1:999998.
335 +9999999:+1:9999998.
336 +99999999:+1:99999998.
337 +999999999:+1:999999998.
338 +9999999999:+1:9999999998.
339 +99999999999:+1:99999999998.
340 +10:-1:11.
341 +100:-1:101.
342 +1000:-1:1001.
343 +10000:-1:10001.
344 +100000:-1:100001.
345 +1000000:-1:1000001.
346 +10000000:-1:10000001.
347 +100000000:-1:100000001.
348 +1000000000:-1:1000000001.
349 +10000000000:-1:10000000001.
350 +123456789:+987654321:-864197532.
351 -123456789:+987654321:-1111111110.
352 -123456789:-987654321:864197532.
353 +123456789:-987654321:1111111110.
354 &fmul
355 abc:abc:
356 abc:+0:
357 +0:abc:
358 +0:+0:0.
359 +0:+1:0.
360 +1:+0:0.
361 +0:-1:0.
362 -1:+0:0.
363 +123456789123456789:+0:0.
364 +0:+123456789123456789:0.
365 -1:-1:1.
366 -1:+1:-1.
367 +1:-1:-1.
368 +1:+1:1.
369 +2:+3:6.
370 -2:+3:-6.
371 +2:-3:-6.
372 -2:-3:6.
373 +111:+111:12321.
374 +10101:+10101:102030201.
375 +1001001:+1001001:1002003002001.
376 +100010001:+100010001:10002000300020001.
377 +10000100001:+10000100001:100002000030000200001.
378 +11111111111:+9:99999999999.
379 +22222222222:+9:199999999998.
380 +33333333333:+9:299999999997.
381 +44444444444:+9:399999999996.
382 +55555555555:+9:499999999995.
383 +66666666666:+9:599999999994.
384 +77777777777:+9:699999999993.
385 +88888888888:+9:799999999992.
386 +99999999999:+9:899999999991.
387 &fdiv
388 abc:abc:
389 abc:+1:abc:
390 +1:abc:
391 +0:+0:
392 +0:+1:0.
393 +1:+0:
394 +0:-1:0.
395 -1:+0:
396 +1:+1:1.
397 -1:-1:1.
398 +1:-1:-1.
399 -1:+1:-1.
400 +1:+2:.5
401 +2:+1:2.
402 +10:+5:2.
403 +100:+4:25.
404 +1000:+8:125.
405 +10000:+16:625.
406 +10000:-16:-625.
407 +999999999999:+9:111111111111.
408 +999999999999:+99:10101010101.
409 +999999999999:+999:1001001001.
410 +999999999999:+9999:100010001.
411 +999999999999999:+99999:10000100001.
412 +1000000000:+9:111111111.1111111111111111111111111111111
413 +2000000000:+9:222222222.2222222222222222222222222222222
414 +3000000000:+9:333333333.3333333333333333333333333333333
415 +4000000000:+9:444444444.4444444444444444444444444444444
416 +5000000000:+9:555555555.5555555555555555555555555555556
417 +6000000000:+9:666666666.6666666666666666666666666666667
418 +7000000000:+9:777777777.7777777777777777777777777777778
419 +8000000000:+9:888888888.8888888888888888888888888888889
420 +9000000000:+9:1000000000.
421 +35500000:+113:314159.2920353982300884955752212389380531
422 +71000000:+226:314159.2920353982300884955752212389380531
423 +106500000:+339:314159.2920353982300884955752212389380531
424 +1000000000:+3:333333333.3333333333333333333333333333333
425 $Math::BigFloat::div_scale = 20
426 +1000000000:+9:111111111.11111111111
427 +2000000000:+9:222222222.22222222222
428 +3000000000:+9:333333333.33333333333
429 +4000000000:+9:444444444.44444444444
430 +5000000000:+9:555555555.55555555556
431 +6000000000:+9:666666666.66666666667
432 +7000000000:+9:777777777.77777777778
433 +8000000000:+9:888888888.88888888889
434 +9000000000:+9:1000000000.
435 +35500000:+113:314159.292035398230088
436 +71000000:+226:314159.292035398230088
437 +106500000:+339:314159.29203539823009
438 +1000000000:+3:333333333.33333333333
439 $Math::BigFloat::div_scale = 40
440 &fsqrt
441 +0:0
442 -1:/^(0|NaN)$
443 -2:/^(0|NaN)$
444 -16:/^(0|NaN)$
445 -123.456:/^(0|NaN)$
446 +1:1.
447 +1.44:1.2
448 +2:1.41421356237309504880168872420969807857
449 +4:2.
450 +16:4.
451 +100:10.
452 +123.456:11.11107555549866648462149404118219234119
453 +15241.383936:123.456