1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#!/usr/bin/perl -w
###############################################################################
use Test;
use strict;
BEGIN
{
$| = 1;
chdir 't' if -d 't';
unshift @INC, '../lib';
plan tests => 20;
}
use bignum;
###############################################################################
# general tests
my $x = 5; ok (ref($x) =~ /^Math::BigInt/); # :constant
ok (2 + 2.5,4.5);
$x = 2 + 3.5; ok (ref($x),'Math::BigFloat');
ok (2 * 2.1,4.2);
$x = 2 + 2.1; ok (ref($x),'Math::BigFloat');
$x = 2 ** 255; ok (ref($x) =~ /^Math::BigInt/);
# see if Math::BigInt constant and upgrading works
ok (Math::BigInt::bsqrt('12'),'3.464101615137754587054892683011744733886');
ok (sqrt(12),'3.464101615137754587054892683011744733886');
ok (2/3,"0.6666666666666666666666666666666666666667");
#ok (2 ** 0.5, 'NaN'); # should be sqrt(2);
ok (12->bfac(),479001600);
# see if Math::BigFloat constant works
# 0123456789 0123456789 <- default 40
# 0123456789 0123456789
ok (1/3, '0.3333333333333333333333333333333333333333');
###############################################################################
# accurarcy and precision
ok_undef (bignum->accuracy());
ok (bignum->accuracy(12),12);
ok (bignum->accuracy(),12);
ok_undef (bignum->precision());
ok (bignum->precision(12),12);
ok (bignum->precision(),12);
ok (bignum->round_mode(),'even');
ok (bignum->round_mode('odd'),'odd');
ok (bignum->round_mode(),'odd');
###############################################################################
###############################################################################
# Perl 5.005 does not like ok ($x,undef)
sub ok_undef
{
my $x = shift;
ok (1,1) and return if !defined $x;
ok ($x,'undef');
}
|