3 # test inf/NaN handling all in one place
4 # Thanx to Jarkko for the excellent explanations and the tables
12 unshift @INC, '../lib';
17 # to locate the testing files
18 my $location = $0; $location =~ s/inf_nan.t//i;
21 @INC = qw(../t/lib); # testing with the core distribution
23 unshift @INC, '../lib'; # for testing manually
28 unshift @INC, File::Spec->catdir(File::Spec->updir, $location);
32 unshift @INC, $location;
34 print "# INC = @INC\n";
36 # values groups oprators classes tests
37 plan tests => 7 * 6 * 5 * 4 * 2 +
38 7 * 6 * 2 * 4 * 1; # bmod
43 use Math::BigInt::Subclass;
44 use Math::BigFloat::Subclass;
47 qw/Math::BigInt Math::BigFloat
48 Math::BigInt::Subclass Math::BigFloat::Subclass
104 @args = split /:/,$_;
105 for my $class (@classes)
107 $x = $class->new($args[0]);
108 $y = $class->new($args[1]);
109 $args[2] = '0' if $args[2] eq '-0'; # BigInt/Float hasn't got -0
110 my $r = $x->badd($y);
112 print "# x $class $args[0] + $args[1] should be $args[2] but is $x\n",
113 if !ok ($x->bstr(),$args[2]);
114 print "# r $class $args[0] + $args[1] should be $args[2] but is $r\n",
115 if !ok ($x->bstr(),$args[2]);
170 @args = split /:/,$_;
171 for my $class (@classes)
173 $x = $class->new($args[0]);
174 $y = $class->new($args[1]);
175 $args[2] = '0' if $args[2] eq '-0'; # BigInt/Float hasn't got -0
176 my $r = $x->bsub($y);
178 print "# x $class $args[0] - $args[1] should be $args[2] but is $x\n"
179 if !ok ($x->bstr(),$args[2]);
180 print "# r $class $args[0] - $args[1] should be $args[2] but is $r\n"
181 if !ok ($r->bstr(),$args[2]);
236 @args = split /:/,$_;
237 for my $class (@classes)
239 $x = $class->new($args[0]);
240 $y = $class->new($args[1]);
241 $args[2] = '0' if $args[2] eq '-0'; # BigInt/Float hasn't got -0
242 $args[2] = '0' if $args[2] eq '-0'; # BigInt hasn't got -0
243 my $r = $x->bmul($y);
245 print "# x $class $args[0] * $args[1] should be $args[2] but is $x\n"
246 if !ok ($x->bstr(),$args[2]);
247 print "# r $class $args[0] * $args[1] should be $args[2] but is $r\n"
248 if !ok ($r->bstr(),$args[2]);
303 @args = split /:/,$_;
304 for my $class (@classes)
306 $x = $class->new($args[0]);
307 $y = $class->new($args[1]);
308 $args[2] = '0' if $args[2] eq '-0'; # BigInt/Float hasn't got -0
311 my $tmod = $t->copy();
313 # bdiv in scalar context
314 my $r = $x->bdiv($y);
315 print "# x $class $args[0] / $args[1] should be $args[2] but is $x\n"
316 if !ok ($x->bstr(),$args[2]);
317 print "# r $class $args[0] / $args[1] should be $args[2] but is $r\n"
318 if !ok ($r->bstr(),$args[2]);
320 # bmod and bdiv in list context
321 my ($d,$rem) = $t->bdiv($y);
323 # bdiv in list context
324 print "# t $class $args[0] / $args[1] should be $args[2] but is $t\n"
325 if !ok ($t->bstr(),$args[2]);
326 print "# d $class $args[0] / $args[1] should be $args[2] but is $d\n"
327 if !ok ($d->bstr(),$args[2]);
330 my $m = $tmod->bmod($y);
332 # bmod() agrees with bdiv?
333 print "# m $class $args[0] % $args[1] should be $rem but is $m\n"
334 if !ok ($m->bstr(),$rem->bstr());
335 # bmod() return agrees with set value?
336 print "# o $class $args[0] % $args[1] should be $m ($rem) but is $tmod\n"
337 if !ok ($tmod->bstr(),$m->bstr());