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