Need to skip optree walking tests if perlio not built
[p5sagit/p5-mst-13.2.git] / lib / Math / BigRat / t / bigratpm.inc
CommitLineData
184f15d5 1#include this file into another test for subclass testing...
2
3ok ($class->config()->{lib},$CL);
4
990fb837 5$setup = '';
6
184f15d5 7while (<DATA>)
8 {
a4e2b1c6 9 chomp;
184f15d5 10 $_ =~ s/#.*$//; # remove comments
11 $_ =~ s/\s+$//; # trailing spaces
12 next if /^$/; # skip empty lines & comments
13 if (s/^&//)
14 {
15 $f = $_;
16 }
17 elsif (/^\$/)
18 {
19 $setup = $_; $setup =~ s/\$/\$${class}::/g; # round_mode, div_scale
20 #print "\$setup== $setup\n";
21 }
22 else
23 {
24 if (m|^(.*?):(/.+)$|)
25 {
26 $ans = $2;
27 @args = split(/:/,$1,99);
28 }
29 else
30 {
31 @args = split(/:/,$_,99); $ans = pop(@args);
32 }
33 $try = "\$x = new $class \"$args[0]\";";
34 if ($f eq "bnorm")
35 {
36 $try .= "\$x;";
37 } elsif ($f eq "finf") {
990fb837 38 my $a = $args[1] || '';
39 $try .= "\$x->binf('$a');";
184f15d5 40 } elsif ($f eq "is_inf") {
41 $try .= "\$x->is_inf('$args[1]');";
42 } elsif ($f eq "fone") {
43 $try .= "\$x->bone('$args[1]');";
44 } elsif ($f eq "fstr") {
45 $try .= "\$x->accuracy($args[1]); \$x->precision($args[2]);";
46 $try .= '$x->bstr();';
47 } elsif ($f eq "parts") {
48 # ->bstr() to see if an object is returned
49 $try .= '($a,$b) = $x->parts(); $a = $a->bstr(); $b = $b->bstr();';
50 $try .= '"$a $b";';
51 } elsif ($f eq "numerator") {
52 # ->bstr() to see if an object is returned
53 $try .= '$x->numerator()->bstr();';
54 } elsif ($f eq "denominator") {
55 # ->bstr() to see if an object is returned
56 $try .= '$x->denominator()->bstr();';
7d341013 57 } elsif ($f =~ /^(length|numify)$/) {
58 $try .= "\$x->$f();";
59 # some unary ops (can't test the fxxx form, since no AUTOLOAD in BigRat)
184f15d5 60 } elsif ($f =~ /^f(nan|sstr|neg|floor|ceil|abs)$/) {
61 $try .= "\$x->b$1();";
62 # some is_xxx test function
63 } elsif ($f =~ /^is_(zero|one|negative|positive|odd|even|nan|int)$/) {
64 $try .= "\$x->$f();";
65 } elsif ($f eq "as_number") {
66 $try .= '$x->as_number();';
67 } elsif ($f eq "finc") {
68 $try .= '++$x;';
69 } elsif ($f eq "fdec") {
70 $try .= '--$x;';
71 }elsif ($f eq "fround") {
72 $try .= "$setup; \$x->bround($args[1]);";
73 } elsif ($f eq "ffround") {
74 $try .= "$setup; \$x->bfround($args[1]);";
75 } elsif ($f eq "fsqrt") {
76 $try .= "$setup; \$x->bsqrt();";
77 } elsif ($f eq "flog") {
78 $try .= "$setup; \$x->blog();";
79 } elsif ($f eq "ffac") {
80 $try .= "$setup; \$x->bfac();";
81 }
82 else
83 {
84 $try .= "\$y = new $class \"$args[1]\";";
7afd7a91 85 if ($f eq "bcmp") {
184f15d5 86 $try .= '$x <=> $y;';
7afd7a91 87 } elsif ($f eq "bacmp") {
184f15d5 88 $try .= '$x->bacmp($y);';
89 } elsif ($f eq "bpow") {
90 $try .= '$x ** $y;';
a4e2b1c6 91 } elsif ($f eq "fpow") {
92 $try .= '$x->bpow($y);';
184f15d5 93 } elsif ($f eq "badd") {
94 $try .= '$x + $y;';
95 } elsif ($f eq "bsub") {
96 $try .= '$x - $y;';
97 } elsif ($f eq "bmul") {
98 $try .= '$x * $y;';
99 } elsif ($f eq "bdiv") {
100 $try .= "$setup; \$x / \$y;";
101 } elsif ($f eq "fdiv-list") {
102 $try .= "$setup; join(',',\$x->bdiv(\$y));";
103 } elsif ($f eq "brsft") {
104 $try .= '$x >> $y;';
105 } elsif ($f eq "blsft") {
106 $try .= '$x << $y;';
107 } elsif ($f eq "bmod") {
108 $try .= '$x % $y;';
7afd7a91 109 } elsif( $f eq "bmodinv") {
110 $try .= "\$x->bmodinv(\$y);";
111 } elsif( $f eq "blog") {
112 $try .= "\$x->blog(\$y);";
113 } else {
114 $try .= "\$z = $class->new(\"$args[2]\");";
115
116 # Functions with three arguments
117 if( $f eq "bmodpow") {
118 $try .= "\$x->bmodpow(\$y,\$z);";
119 } else { warn "Unknown op '$f'"; }
120 }
184f15d5 121 }
122 # print "# Trying: '$try'\n";
123 $ans1 = eval $try;
124 if ($ans =~ m|^/(.*)$|)
125 {
126 my $pat = $1;
127 if ($ans1 =~ /$pat/)
128 {
129 ok (1,1);
130 }
131 else
132 {
133 print "# '$try' expected: /$pat/ got: '$ans1'\n" if !ok(1,0);
134 }
135 }
136 else
137 {
138 if ($ans eq "")
139 {
140 ok_undef ($ans1);
141 }
142 else
143 {
144 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
145# if (ref($ans1) eq "$class")
146# {
147# # float numbers are normalized (for now), so mantissa shouldn't have
148# # trailing zeros
149# #print $ans1->_trailing_zeros(),"\n";
150# print "# Has trailing zeros after '$try'\n"
151# if !ok ($ans1->{_m}->_trailing_zeros(), 0);
152# }
153 }
154 } # end pattern or string
155 }
156 } # end while
157
158# check whether $class->new( Math::BigInt->new()) destroys it
159# ($y == 12 in this case)
160$x = Math::BigInt->new(1200); $y = $class->new($x);
161ok ($y,1200); ok ($x,1200);
162
163###############################################################################
164# zero,inf,one,nan
165
166$x = $class->new(2); $x->bzero(); ok_undef ($x->{_a}); ok_undef ($x->{_p});
167$x = $class->new(2); $x->binf(); ok_undef ($x->{_a}); ok_undef ($x->{_p});
168$x = $class->new(2); $x->bone(); ok_undef ($x->{_a}); ok_undef ($x->{_p});
169$x = $class->new(2); $x->bnan(); ok_undef ($x->{_a}); ok_undef ($x->{_p});
170
1711; # all done
172
173###############################################################################
174# Perl 5.005 does not like ok ($x,undef)
175
176sub ok_undef
177 {
178 my $x = shift;
179
180 ok (1,1) and return if !defined $x;
181 ok ($x,'undef');
182 }
183
184__DATA__
7afd7a91 185&bmodinv
186# format: number:modulus:result
187# bmodinv Data errors
188abc:abc:NaN
189abc:5:NaN
1905:abc:NaN
191# bmodinv Expected Results from normal use
1921:5:1
1933:5:2
194-2:5:2
1958:5033:4404
1961234567891:13:6
197-1234567891:13:7
198324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
199## bmodinv Error cases / useless use of function
2003:-5:NaN
201inf:5:NaN
2025:inf:NaN
203-inf:5:NaN
2045:-inf:NaN
990fb837 205&as_number
206144/7:20
207NaN:NaN
208+inf:inf
209-inf:-inf
7afd7a91 210&bmodpow
211# format: number:exponent:modulus:result
212# bmodpow Data errors
213abc:abc:abc:NaN
2145:abc:abc:NaN
215abc:5:abc:NaN
216abc:abc:5:NaN
2175:5:abc:NaN
2185:abc:5:NaN
219abc:5:5:NaN
220# bmodpow Expected results
2210:0:2:1
2221:0:2:1
2230:0:1:0
2248:7:5032:3840
2258:-1:5033:4404
22698436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
227# bmodpow Error cases
2288:8:-5:NaN
2298:-1:16:NaN
230inf:5:13:NaN
2315:inf:13:NaN
990fb837 232&bmod
233NaN:1:NaN
2341:NaN:NaN
2351:1:0
2362:2:0
23712:6:0
2387/4:4/14:1/28
2397/4:4/16:0
240-7/4:4/16:0
241-7/4:-4/16:0
2427/4:-4/16:0
2437/4:4/32:0
244-7/4:4/32:0
245-7/4:-4/32:0
2467/4:-4/32:0
2477/4:4/28:1/28
248-7/4:4/28:-1/28
2497/4:-4/28:1/28
250-7/4:-4/28:-1/28
251&fsqrt
2521:1
2530:0
254NaN:NaN
255+inf:inf
256-inf:NaN
257144:12
258# sqrt(144) / sqrt(4) = 12/2 = 6/1
259144/4:6
26025/16:5/4
261-3:NaN
262&flog
263NaN:NaN
2640:NaN
7afd7a91 265-2:NaN
266&blog
267NaN:NaN:NaN
2680:NaN:NaN
269NaN:0:NaN
270NaN:1:NaN
2711:NaN:NaN
2720:2:NaN
2730:-2:NaN
2743:-2:NaN
184f15d5 275&finf
2761:+:inf
2772:-:-inf
2783:abc:inf
990fb837 279&numify
93c87d9d 2800:0
281+1:1
2821234:1234
2833/4:0.75
2845/2:2.5
2853/2:1.5
2865/4:1.25
990fb837 287NaN:NaN
93c87d9d 288+inf:inf
289-inf:-inf
184f15d5 290&fnan
291abc:NaN
2922:NaN
293-2:NaN
2940:NaN
295&fone
2962:+:1
297-2:-:-1
298-2:+:1
2992:-:-1
3000::1
301-2::1
302abc::1
3032:abc:1
304&fsstr
305+inf:inf
306-inf:-inf
307abcfsstr:NaN
3081:1/1
3093/1:3/1
3100.1:1/10
311&bnorm
3121:1
313-0:0
314bnormNaN:NaN
315+inf:inf
316-inf:-inf
7afd7a91 317inf/inf:NaN
3185/inf:0
3195/-inf:0
320inf/5:inf
321-inf/5:-inf
322inf/-5:-inf
323-inf/-5:inf
184f15d5 324123:123
325-123.4567:-1234567/10000
326# invalid inputs
3271__2:NaN
3281E1__2:NaN
32911__2E2:NaN
330#1.E3:NaN
331.2E-3.:NaN
332#1e3e4:NaN
333.2E2:20
334inf:inf
335+inf:inf
336-inf:-inf
337+infinity:NaN
338+-inf:NaN
339abc:NaN
340 1 a:NaN
3411bcd2:NaN
34211111b:NaN
343+1z:NaN
344-1z:NaN
3450:0
346+0:0
347+00:0
348+0_0_0:0
349000000_0000000_00000:0
350-0:0
351-0000:0
352+1:1
353+01:1
354+001:1
355+00000100000:100000
356123456789:123456789
357-1:-1
358-01:-1
359-001:-1
360-123456789:-123456789
361-00000100000:-100000
362123.456a:NaN
363123.456:15432/125
3640.01:1/100
365.002:1/500
366+.2:1/5
367-0.0003:-3/10000
368-.0000000004:-1/2500000000
369123456E2:12345600
370123456E-2:30864/25
371-123456E2:-12345600
372-123456E-2:-30864/25
3731e1:10
3742e-11:1/50000000000
37512/10:6/5
3760.1/0.1:1
377100/0.1:1000
3780.1/10:1/100
3791 / 3:1/3
3801/ 3:1/3
3811 /3:1/3
382&fneg
383fnegNaN:NaN
384+inf:-inf
385-inf:inf
386+0:0
387+1:-1
388-1:1
389+123456789:-123456789
390-123456789:123456789
391+123.456789:-123456789/1000000
392-123456.789:123456789/1000
393&fabs
394fabsNaN:NaN
395+inf:inf
396-inf:inf
397+0:0
398+1:1
399-1:1
400+123456789:123456789
401-123456789:123456789
402+123.456789:123456789/1000000
403-123456.789:123456789/1000
404&badd
405abc:abc:NaN
406abc:+0:NaN
407+0:abc:NaN
408+inf:-inf:NaN
409-inf:+inf:NaN
410+inf:+inf:inf
411-inf:-inf:-inf
412baddNaN:+inf:NaN
413baddNaN:+inf:NaN
414+inf:baddNaN:NaN
415-inf:baddNaN:NaN
416+0:+0:0
417+1:+0:1
418+0:+1:1
419+1:+1:2
420-1:+0:-1
421+0:-1:-1
422-1:-1:-2
423-1:+1:0
424+1:-1:0
425+9:+1:10
426+99:+1:100
427+999:+1:1000
428+9999:+1:10000
429+99999:+1:100000
430+999999:+1:1000000
431+9999999:+1:10000000
432+99999999:+1:100000000
433+999999999:+1:1000000000
434+9999999999:+1:10000000000
435+99999999999:+1:100000000000
436+10:-1:9
437+100:-1:99
438+1000:-1:999
439+10000:-1:9999
440+100000:-1:99999
441+1000000:-1:999999
442+10000000:-1:9999999
443+100000000:-1:99999999
444+1000000000:-1:999999999
445+10000000000:-1:9999999999
446+123456789:+987654321:1111111110
447-123456789:+987654321:864197532
448-123456789:-987654321:-1111111110
449+123456789:-987654321:-864197532
4501/3:1/3:2/3
4512/3:-1/3:1/3
452&bsub
453abc:abc:NaN
454abc:+0:NaN
455+0:abc:NaN
456+inf:-inf:inf
457-inf:+inf:-inf
458+inf:+inf:NaN
459-inf:-inf:NaN
460baddNaN:+inf:NaN
461baddNaN:+inf:NaN
462+inf:baddNaN:NaN
463-inf:baddNaN:NaN
464+0:+0:0
465+1:+0:1
466+0:+1:-1
467+1:+1:0
468-1:+0:-1
469+0:-1:1
470-1:-1:0
471-1:+1:-2
472+1:-1:2
473+9:+1:8
474+99:+1:98
475+999:+1:998
476+9999:+1:9998
477+99999:+1:99998
478+999999:+1:999998
479+9999999:+1:9999998
480+99999999:+1:99999998
481+999999999:+1:999999998
482+9999999999:+1:9999999998
483+99999999999:+1:99999999998
484+10:-1:11
485+100:-1:101
486+1000:-1:1001
487+10000:-1:10001
488+100000:-1:100001
489+1000000:-1:1000001
490+10000000:-1:10000001
491+100000000:-1:100000001
492+1000000000:-1:1000000001
493+10000000000:-1:10000000001
494+123456789:+987654321:-864197532
495-123456789:+987654321:-1111111110
496-123456789:-987654321:864197532
497+123456789:-987654321:1111111110
4982/3:1/3:1/3
4997/27:3/54:11/54
500-2/3:+2/3:-4/3
501-2/3:-2/3:0
7afd7a91 5020:-123:123
5030:123:-123
184f15d5 504&bmul
505abc:abc:NaN
506abc:+0:NaN
507+0:abc:NaN
508+inf:NaNmul:NaN
509+inf:NaNmul:NaN
510NaNmul:+inf:NaN
511NaNmul:-inf:NaN
512+inf:+inf:inf
513+inf:-inf:-inf
514+inf:-inf:-inf
515+inf:+inf:inf
516+inf:123.34:inf
517+inf:-123.34:-inf
518-inf:123.34:-inf
519-inf:-123.34:inf
520123.34:+inf:inf
521-123.34:+inf:-inf
522123.34:-inf:-inf
523-123.34:-inf:inf
524+0:+0:0
525+0:+1:0
526+1:+0:0
527+0:-1:0
528-1:+0:0
529+123456789123456789:+0:0
530+0:+123456789123456789:0
531-1:-1:1
532-1:+1:-1
533+1:-1:-1
534+1:+1:1
535+2:+3:6
536-2:+3:-6
537+2:-3:-6
538-2:-3:6
539+111:+111:12321
540+10101:+10101:102030201
541+1001001:+1001001:1002003002001
542+100010001:+100010001:10002000300020001
543+10000100001:+10000100001:100002000030000200001
544+11111111111:+9:99999999999
545+22222222222:+9:199999999998
546+33333333333:+9:299999999997
547+44444444444:+9:399999999996
548+55555555555:+9:499999999995
549+66666666666:+9:599999999994
550+77777777777:+9:699999999993
551+88888888888:+9:799999999992
552+99999999999:+9:899999999991
5536:120:720
55410:10000:100000
5551/4:1/3:1/12
556&bdiv
557$div_scale = 40; $round_mode = 'even'
558abc:abc:NaN
559abc:+1:abc:NaN
560+1:abc:NaN
561-1:abc:NaN
5620:abc:NaN
563+0:+0:NaN
564+0:+1:0
565+1:+0:inf
566+3214:+0:inf
567+0:-1:0
568-1:+0:-inf
569-3214:+0:-inf
570+1:+1:1
571-1:-1:1
572+1:-1:-1
573-1:+1:-1
574+1:+2:1/2
575+2:+1:2
576123:+inf:0
577123:-inf:0
578+10:+5:2
579+100:+4:25
580+1000:+8:125
581+10000:+16:625
582+10000:-16:-625
583+999999999999:+9:111111111111
584+999999999999:+99:10101010101
585+999999999999:+999:1001001001
586+999999999999:+9999:100010001
587+999999999999999:+99999:10000100001
588+1000000000:+9:1000000000/9
589+2000000000:+9:2000000000/9
590+3000000000:+9:1000000000/3
591+4000000000:+9:4000000000/9
592+5000000000:+9:5000000000/9
593+6000000000:+9:2000000000/3
594+7000000000:+9:7000000000/9
595+8000000000:+9:8000000000/9
596+9000000000:+9:1000000000
597+35500000:+113:35500000/113
598+71000000:+226:35500000/113
599+106500000:+339:35500000/113
600+1000000000:+3:1000000000/3
6012:25.024996000799840031993601279744051189762:1000000000000000000000000000000000000000/12512498000399920015996800639872025594881
602123456:1:123456
6031/4:1/3:3/4
604# reset scale for further tests
605$div_scale = 40
606&is_nan
607123:0
608abc:1
609NaN:1
610-123:0
611&is_inf
612+inf::1
613-inf::1
614abc::0
6151::0
616NaN::0
617-1::0
618+inf:-:0
619+inf:+:1
620-inf:-:1
621-inf:+:0
622# it must be exactly /^[+-]inf$/
623+infinity::0
624-infinity::0
625&is_odd
626abc:0
6270:0
628-1:1
629-3:1
6301:1
6313:1
6321000001:1
6331000002:0
634+inf:0
635-inf:0
636123.45:0
637-123.45:0
6382:0
639&is_int
640NaNis_int:0
6410:1
6421:1
6432:1
644-2:1
645-1:1
646-inf:0
647+inf:0
648123.4567:0
649-0.1:0
650-0.002:0
6511/3:0
6523/1:1
653&is_even
654abc:0
6550:1
656-1:0
657-3:0
6581:0
6593:0
6601000001:0
6611000002:1
6622:1
663+inf:0
664-inf:0
665123.456:0
666-123.456:0
6670.01:0
668-0.01:0
669120:1
6701200:1
671-1200:1
672&is_positive
6730:1
6741:1
675-1:0
676-123:0
677NaN:0
678-inf:0
679+inf:1
680&is_negative
6810:0
6821:0
683-1:1
684-123:1
685NaN:0
686-inf:1
687+inf:0
a4e2b1c6 688&parts
6890:0 1
6901:1 1
691123:123 1
692-123:-123 1
693-1200:-1200 1
6945/7:5 7
695-5/7:-5 7
696NaNparts:NaN NaN
697+inf:inf inf
698-inf:-inf inf
184f15d5 699#&exponent
700#0:1
701#1:0
702#123:0
703#-123:0
704#-1200:2
705#+inf:inf
706#-inf:inf
707#NaNexponent:NaN
708#&mantissa
709#0:0
710#1:1
711#123:123
712#-123:-123
713#-1200:-12
714#+inf:inf
715#-inf:-inf
716#NaNmantissa:NaN
717#&length
718#123:3
719#-123:3
720#0:1
721#1:1
722#12345678901234567890:20
723&is_zero
724NaNzero:0
725+inf:0
726-inf:0
7270:1
728-1:0
7291:0
7300/3:1
7311/3:0
7afd7a91 732-0/3:1
7335/inf:1
184f15d5 734&is_one
735NaNone:0
736+inf:0
737-inf:0
7380:0
7392:0
7401:1
741-1:0
742-2:0
7431/3:0
744100/100:1
7450.1/0.1:1
7afd7a91 7465/inf:0
184f15d5 747&ffloor
7480:0
749abc:NaN
750+inf:inf
751-inf:-inf
7521:1
753-51:-51
754-51.2:-52
75512.2:12
a4e2b1c6 7563/7:0
7576/7:0
7587/7:1
7598/7:1
76013/7:1
76114/7:2
76215/7:2
763-3/7:-1
764-6/7:-1
765-7/1:-7
766-8/7:-2
767-13/7:-2
768-14/7:-2
769-15/7:-3
184f15d5 770&fceil
7710:0
772abc:NaN
773+inf:inf
774-inf:-inf
7751:1
776-51:-51
777-51.2:-51
77812.2:13
a4e2b1c6 7793/7:1
7806/7:1
7818/7:2
78213/7:2
78314/7:2
78415/7:3
785-3/7:0
786-6/7:0
787-8/7:-1
788-13/7:-1
789-14/7:-2
790-15/7:-2
791&ffac
792NaN:NaN
7931:1
794-1:NaN
795&bpow
796# bpow test for overload of **
7972:2:4
7983:3:27
7afd7a91 799&bacmp
800+0:-0:0
801+0:+1:-1
802-1:+1:0
803+1:-1:0
804-1:+2:-1
805+2:-1:1
806-123456789:+987654321:-1
807+123456789:-987654321:-1
808+987654321:+123456789:1
809-987654321:+123456789:1
810-123:+4567889:-1
811# NaNs
812acmpNaN:123:
813123:acmpNaN:
814acmpNaN:acmpNaN:
815# infinity
816+inf:+inf:0
817-inf:-inf:0
818+inf:-inf:0
819-inf:+inf:0
820+inf:123:1
821-inf:123:1
822+inf:-123:1
823-inf:-123:1
824+inf:1/23:1
825-inf:1/23:1
826+inf:-1/23:1
827-inf:-1/23:1
828+inf:12/3:1
829-inf:12/3:1
830+inf:-12/3:1
831-inf:-12/3:1
832123:inf:-1
833-123:inf:-1
834123:-inf:-1
835-123:-inf:-1
8361/23:inf:-1
837-1/23:inf:-1
8381/23:-inf:-1
839-1/23:-inf:-1
84012/3:inf:-1
841-12/3:inf:-1
84212/3:-inf:-1
843-12/3:-inf:-1
844# return undef
845+inf:NaN:
846NaN:inf:
847-inf:NaN:
848NaN:-inf:
8491/3:2/3:-1
8502/3:1/3:1
8512/3:2/3:0
a4e2b1c6 852&fpow
8532/1:3/1:8
8543/1:3/1:27
8555/2:3/1:125/8
856-2/1:3/1:-8
857-3/1:3/1:-27
858-5/2:3/1:-125/8
859-2/1:4/1:16
860-3/1:4/1:81
861-5/2:4/1:625/16
862-5/2:-4/1:16/625
8631/5:-3:125
864-1/5:-3:-125
865&numerator
866NaN:NaN
867inf:inf
868-inf:-inf
8693/7:3
870-3/7:-3
8710:0
8721:1
873&denominator
874NaN:NaN
875inf:inf
876-inf:-inf
8773/7:7
8780:1
8791/1:1
880-3/7:7
881&finc
8823/2:5/2
883-15/6:-3/2
884NaN:NaN
885-1/3:2/3
886-2/7:5/7
887&fdec
88815/6:3/2
889-3/2:-5/2
8901/3:-2/3
8912/7:-5/7
892NaN:NaN