This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
The first big import towards 5.8.1, @18078. Please do NOT
[perl5.git] / lib / Math / BigRat / t / big_ap.t
1 #!/usr/bin/perl -w
2
3 use Test;
4 use strict;
5
6 BEGIN
7   {
8   $| = 1;
9   chdir 't' if -d 't';
10   unshift @INC, '../lib';
11   plan tests => 17;
12   }
13
14 use Math::BigInt;
15 use Math::BigFloat;
16 use Math::BigRat;
17
18 my $r = 'Math::BigRat';
19 my $proper = $r->new('12345678901234567890/2');
20 my $proper_inc = $r->new('12345678901234567890/2')->binc();
21 my $proper_dec = $r->new('12345678901234567890/2')->bdec();
22 my $proper_int = Math::BigInt->new('12345678901234567890');
23 my $proper_float = Math::BigFloat->new('12345678901234567890');
24 my $proper2 = $r->new('12345678901234567890');
25
26 print "# Start\n";
27
28 Math::BigInt->accuracy(3);
29 Math::BigFloat->accuracy(5);
30
31 my ($x,$y,$z);
32
33 ##############################################################################
34 # new()
35
36 $z = $r->new('12345678901234567890/2');
37 ok ($z,$proper);
38
39 $z = $r->new('1234567890123456789E1');
40 ok ($z,$proper2);
41
42 $z = $r->new('12345678901234567890/1E0');
43 ok ($z,$proper2);
44 $z = $r->new('1234567890123456789e1/1');
45 ok ($z,$proper2);
46 $z = $r->new('1234567890123456789e1/1E0');
47 ok ($z,$proper2);
48
49 $z = $r->new($proper_int);
50 ok ($z,$proper2);
51
52 $z = $r->new($proper_float);
53 ok ($z,$proper2);
54
55 ##############################################################################
56 # bdiv
57
58 $x = $r->new('12345678901234567890'); $y = Math::BigRat->new('2');
59 $z = $x->copy->bdiv($y);
60 ok ($z,$proper);
61
62 ##############################################################################
63 # bmul
64
65 $x = $r->new("$proper"); $y = Math::BigRat->new('1');
66 $z = $x->copy->bmul($y);
67 ok ($z,$proper);
68 $z = $r->new('12345678901234567890/1E0');
69 ok ($z,$proper2);
70
71 $z = $r->new($proper_int);
72 ok ($z,$proper2);
73
74 $z = $r->new($proper_float);
75 ok ($z,$proper2);
76
77 ##############################################################################
78 # bdiv
79
80 $x = $r->new('12345678901234567890'); $y = Math::BigRat->new('2');
81 $z = $x->copy->bdiv($y);
82 ok ($z,$proper);
83
84 ##############################################################################
85 # bmul
86
87 $x = $r->new("$proper"); $y = Math::BigRat->new('1');
88 $z = $x->copy->bmul($y);
89 ok ($z,$proper);
90
91 $x = $r->new("$proper"); $y = Math::BigRat->new('2');
92 $z = $x->copy->bmul($y);
93 ok ($z,$proper2);
94
95 ##############################################################################
96 # binc
97
98 $x = $proper->copy()->binc(); ok ($x,$proper_inc);
99 $x = $proper->copy()->bdec(); ok ($x,$proper_dec);
100