3 # test inf/NaN handling all in one place
4 # Thanx to Jarkko for the excellent explanations and the tables
12 # to locate the testing files
13 my $location = $0; $location =~ s/inf_nan.t//i;
16 @INC = qw(../t/lib); # testing with the core distribution
18 unshift @INC, '../lib'; # for testing manually
23 unshift @INC, File::Spec->catdir(File::Spec->updir, $location);
27 unshift @INC, $location;
29 print "# INC = @INC\n";
31 # values groups operators classes tests
32 plan tests => 7 * 6 * 5 * 4 * 2 +
33 7 * 6 * 2 * 4 * 1 # bmod
35 # see bottom: + 4 * 10; # 4 classes * 10 NaN == NaN tests
40 use Math::BigInt::Subclass;
41 use Math::BigFloat::Subclass;
44 qw/Math::BigInt Math::BigFloat
45 Math::BigInt::Subclass Math::BigFloat::Subclass
101 @args = split /:/,$_;
102 for my $class (@classes)
104 $x = $class->new($args[0]);
105 $y = $class->new($args[1]);
106 $args[2] = '0' if $args[2] eq '-0'; # BigInt/Float hasn't got -0
107 my $r = $x->badd($y);
109 is($x->bstr(),$args[2],"x $class $args[0] + $args[1]");
110 is($x->bstr(),$args[2],"r $class $args[0] + $args[1]");
165 @args = split /:/,$_;
166 for my $class (@classes)
168 $x = $class->new($args[0]);
169 $y = $class->new($args[1]);
170 $args[2] = '0' if $args[2] eq '-0'; # BigInt/Float hasn't got -0
171 my $r = $x->bsub($y);
173 is($x->bstr(),$args[2],"x $class $args[0] - $args[1]");
174 is($r->bstr(),$args[2],"r $class $args[0] - $args[1]");
229 @args = split /:/,$_;
230 for my $class (@classes)
232 $x = $class->new($args[0]);
233 $y = $class->new($args[1]);
234 $args[2] = '0' if $args[2] eq '-0'; # BigInt/Float hasn't got -0
235 $args[2] = '0' if $args[2] eq '-0'; # BigInt hasn't got -0
236 my $r = $x->bmul($y);
238 is($x->bstr(),$args[2],"x $class $args[0] * $args[1]");
239 is($r->bstr(),$args[2],"r $class $args[0] * $args[1]");
294 @args = split /:/,$_;
295 for my $class (@classes)
297 $x = $class->new($args[0]);
298 $y = $class->new($args[1]);
299 $args[2] = '0' if $args[2] eq '-0'; # BigInt/Float hasn't got -0
302 my $tmod = $t->copy();
304 # bdiv in scalar context
305 my $r = $x->bdiv($y);
306 is($x->bstr(),$args[2],"x $class $args[0] / $args[1]");
307 is($r->bstr(),$args[2],"r $class $args[0] / $args[1]");
309 # bmod and bdiv in list context
310 my ($d,$rem) = $t->bdiv($y);
312 # bdiv in list context
313 is($t->bstr(),$args[2],"t $class $args[0] / $args[1]");
314 is($d->bstr(),$args[2],"d $class $args[0] / $args[1]");
317 my $m = $tmod->bmod($y);
319 # bmod() agrees with bdiv?
320 is($m->bstr(),$rem->bstr(),"m $class $args[0] % $args[1]");
321 # bmod() return agrees with set value?
322 is($tmod->bstr(),$m->bstr(),"o $class $args[0] % $args[1]");
327 #############################################################################
328 # overloaded comparisations
330 # these are disabled for now, since Perl itself can't seem to make up it's
331 # mind what NaN actually is, see [perl #33106].
334 #foreach my $c (@classes)
336 # my $x = $c->bnan();
337 # my $y = $c->bnan(); # test with two different objects, too
338 # my $a = $c->bzero();
340 # is ($x == $y, undef, 'NaN == NaN: undef');
341 # is ($x != $y, 1, 'NaN != NaN: 1');
343 # is ($x == $x, undef, 'NaN == NaN: undef');
344 # is ($x != $x, 1, 'NaN != NaN: 1');
346 # is ($a != $x, 1, '0 != NaN: 1');
347 # is ($a == $x, undef, '0 == NaN: undef');
349 # is ($a < $x, undef, '0 < NaN: undef');
350 # is ($a <= $x, undef, '0 <= NaN: undef');
351 # is ($a >= $x, undef, '0 >= NaN: undef');
352 # is ($a > $x, undef, '0 > NaN: undef');