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