bignum 0.22 take 4 (hex()/oct() overloading)
[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';
d1a15766 13 plan tests => 35;
126f3c5f 14 }
15
d1a15766 16use bignum qw/oct hex/;
126f3c5f 17
18###############################################################################
19# general tests
20
21my $x = 5; ok (ref($x) =~ /^Math::BigInt/); # :constant
22
8f675a64 23ok (2 + 2.5,4.5);
24$x = 2 + 3.5; ok (ref($x),'Math::BigFloat');
25ok (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 31ok (Math::BigInt::bsqrt('12'),'3.464101615137754587054892683011744733886');
126f3c5f 32ok (sqrt(12),'3.464101615137754587054892683011744733886');
33
34ok (2/3,"0.6666666666666666666666666666666666666667");
35
36#ok (2 ** 0.5, 'NaN'); # should be sqrt(2);
37
38ok (12->bfac(),479001600);
39
40# see if Math::BigFloat constant works
41
42# 0123456789 0123456789 <- default 40
43# 0123456789 0123456789
44ok (1/3, '0.3333333333333333333333333333333333333333');
45
46###############################################################################
47# accurarcy and precision
48
990fb837 49ok_undef (bignum->accuracy());
50ok (bignum->accuracy(12),12);
51ok (bignum->accuracy(),12);
52
53ok_undef (bignum->precision());
54ok (bignum->precision(12),12);
55ok (bignum->precision(),12);
56
57ok (bignum->round_mode(),'even');
58ok (bignum->round_mode('odd'),'odd');
59ok (bignum->round_mode(),'odd');
126f3c5f 60
61###############################################################################
d1a15766 62# hex() and oct()
63
64my $c = 'Math::BigInt';
65
66ok (ref(hex(1)), $c);
67ok (ref(hex(0x1)), $c);
68ok (ref(hex("af")), $c);
69ok (hex("af"), Math::BigInt->new(0xaf));
70ok (ref(hex("0x1")), $c);
71
72ok (ref(oct("0x1")), $c);
73ok (ref(oct("01")), $c);
74ok (ref(oct("0b01")), $c);
75ok (ref(oct("1")), $c);
76ok (ref(oct(" 1")), $c);
77ok (ref(oct(" 0x1")), $c);
78
79ok (ref(oct(0x1)), $c);
80ok (ref(oct(01)), $c);
81ok (ref(oct(0b01)), $c);
82ok (ref(oct(1)), $c);
83
84###############################################################################
126f3c5f 85###############################################################################
86# Perl 5.005 does not like ok ($x,undef)
87
88sub ok_undef
89 {
90 my $x = shift;
91
92 ok (1,1) and return if !defined $x;
93 ok ($x,'undef');
94 }