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