10 unshift @INC, '../lib'; # for running manually
14 # testing of Math::BigRat
20 $x = Math::BigRat->new(1234); ok ($x,1234);
21 ok ($x->isa('Math::BigRat'));
22 ok (!$x->isa('Math::BigFloat'));
23 ok (!$x->isa('Math::BigInt'));
25 ##############################################################################
28 $x = Math::BigRat->new(1234); ok ($x,1234);
29 $x = Math::BigRat->new('1234/1'); ok ($x,1234);
30 $x = Math::BigRat->new('1234/2'); ok ($x,617);
32 $x = Math::BigRat->new('100/1.0'); ok ($x,100);
33 $x = Math::BigRat->new('10.0/1.0'); ok ($x,10);
34 $x = Math::BigRat->new('0.1/10'); ok ($x,'1/100');
35 $x = Math::BigRat->new('0.1/0.1'); ok ($x,'1');
36 $x = Math::BigRat->new('1e2/10'); ok ($x,10);
37 $x = Math::BigRat->new('1e2/1e1'); ok ($x,10);
38 $x = Math::BigRat->new('1 / 3'); ok ($x,'1/3');
39 $x = Math::BigRat->new('-1 / 3'); ok ($x,'-1/3');
40 $x = Math::BigRat->new('NaN'); ok ($x,'NaN');
41 $x = Math::BigRat->new('inf'); ok ($x,'inf');
42 $x = Math::BigRat->new('-inf'); ok ($x,'-inf');
43 $x = Math::BigRat->new('1/'); ok ($x,'NaN');
45 # input ala '1+1/3' isn't parsed ok yet
46 $x = Math::BigRat->new('1+1/3'); ok ($x,'NaN');
48 ##############################################################################
51 ok (Math::BigRat->new('3/7')->badd(1),'10/7');
52 ok (Math::BigRat->new('3/10')->badd(1.1),'7/5');
53 ok (Math::BigRat->new('3/7')->badd(Math::BigInt->new(1)),'10/7');
54 ok (Math::BigRat->new('3/10')->badd(Math::BigFloat->new('1.1')),'7/5');
56 ok (Math::BigRat->new('3/7')->bsub(1),'-4/7');
57 ok (Math::BigRat->new('3/10')->bsub(1.1),'-4/5');
58 ok (Math::BigRat->new('3/7')->bsub(Math::BigInt->new(1)),'-4/7');
59 ok (Math::BigRat->new('3/10')->bsub(Math::BigFloat->new('1.1')),'-4/5');
61 ok (Math::BigRat->new('3/7')->bmul(1),'3/7');
62 ok (Math::BigRat->new('3/10')->bmul(1.1),'33/100');
63 ok (Math::BigRat->new('3/7')->bmul(Math::BigInt->new(1)),'3/7');
64 ok (Math::BigRat->new('3/10')->bmul(Math::BigFloat->new('1.1')),'33/100');
66 ok (Math::BigRat->new('3/7')->bdiv(1),'3/7');
67 ok (Math::BigRat->new('3/10')->bdiv(1.1),'3/11');
68 ok (Math::BigRat->new('3/7')->bdiv(Math::BigInt->new(1)),'3/7');
69 ok (Math::BigRat->new('3/10')->bdiv(Math::BigFloat->new('1.1')),'3/11');
71 ##############################################################################
72 $x = Math::BigRat->new('1/4'); $y = Math::BigRat->new('1/3');
77 $x = Math::BigRat->new('7/5'); $x *= '3/2';
80 ok ($x,'2'); # not 21/10
82 $x = Math::BigRat->new('2/3'); $y = Math::BigRat->new('3/2');
87 $x = Math::BigRat->new('-2/3'); $y = Math::BigRat->new('3/2');
92 $x = Math::BigRat->new('-2/3'); $y = Math::BigRat->new('-2/3');
97 $x = Math::BigRat->new('-2/3'); $y = Math::BigRat->new('-1/3');
102 $x = Math::BigRat->new('-124'); $y = Math::BigRat->new('-122');
103 ok ($x->bacmp($y),1);
105 $x = Math::BigRat->new('-124'); $y = Math::BigRat->new('-122');
106 ok ($x->bcmp($y),-1);
108 $x = Math::BigRat->new('3/7'); $y = Math::BigRat->new('5/7');
111 $x = Math::BigRat->new('3/7'); $y = Math::BigRat->new('5/7');
114 $x = Math::BigRat->new('3/5'); $y = Math::BigRat->new('5/7');
117 $x = Math::BigRat->new('3/5'); $y = Math::BigRat->new('5/7');
120 $x = Math::BigRat->new('-144/9'); $x->bsqrt(); ok ($x,'NaN');
121 $x = Math::BigRat->new('144/9'); $x->bsqrt(); ok ($x,'4');