Commit | Line | Data |
---|---|---|
7d341013 T |
1 | #!/usr/bin/perl -w |
2 | ||
12fc2493 AMS |
3 | # Test that accuracy() and precision() in BigInt/BigFloat do not disturb |
4 | # the rounding force in BigRat. | |
5 | ||
7d341013 | 6 | use strict; |
c32198f6 | 7 | use Test::More tests => 17; |
7d341013 T |
8 | |
9 | use Math::BigInt; | |
10 | use Math::BigFloat; | |
11 | use Math::BigRat; | |
12 | ||
13 | my $r = 'Math::BigRat'; | |
14 | my $proper = $r->new('12345678901234567890/2'); | |
15 | my $proper_inc = $r->new('12345678901234567890/2')->binc(); | |
16 | my $proper_dec = $r->new('12345678901234567890/2')->bdec(); | |
17 | my $proper_int = Math::BigInt->new('12345678901234567890'); | |
18 | my $proper_float = Math::BigFloat->new('12345678901234567890'); | |
19 | my $proper2 = $r->new('12345678901234567890'); | |
20 | ||
21 | print "# Start\n"; | |
22 | ||
23 | Math::BigInt->accuracy(3); | |
24 | Math::BigFloat->accuracy(5); | |
25 | ||
26 | my ($x,$y,$z); | |
27 | ||
28 | ############################################################################## | |
29 | # new() | |
30 | ||
31 | $z = $r->new('12345678901234567890/2'); | |
c32198f6 | 32 | is ($z,$proper); |
7d341013 T |
33 | |
34 | $z = $r->new('1234567890123456789E1'); | |
c32198f6 | 35 | is ($z,$proper2); |
7d341013 T |
36 | |
37 | $z = $r->new('12345678901234567890/1E0'); | |
c32198f6 | 38 | is ($z,$proper2); |
7d341013 | 39 | $z = $r->new('1234567890123456789e1/1'); |
c32198f6 | 40 | is ($z,$proper2); |
7d341013 | 41 | $z = $r->new('1234567890123456789e1/1E0'); |
c32198f6 | 42 | is ($z,$proper2); |
7d341013 T |
43 | |
44 | $z = $r->new($proper_int); | |
c32198f6 | 45 | is ($z,$proper2); |
7d341013 T |
46 | |
47 | $z = $r->new($proper_float); | |
c32198f6 | 48 | is ($z,$proper2); |
7d341013 T |
49 | |
50 | ############################################################################## | |
51 | # bdiv | |
52 | ||
53 | $x = $r->new('12345678901234567890'); $y = Math::BigRat->new('2'); | |
54 | $z = $x->copy->bdiv($y); | |
c32198f6 | 55 | is ($z,$proper); |
7d341013 T |
56 | |
57 | ############################################################################## | |
58 | # bmul | |
59 | ||
60 | $x = $r->new("$proper"); $y = Math::BigRat->new('1'); | |
61 | $z = $x->copy->bmul($y); | |
c32198f6 | 62 | is ($z,$proper); |
7d341013 | 63 | $z = $r->new('12345678901234567890/1E0'); |
c32198f6 | 64 | is ($z,$proper2); |
7d341013 T |
65 | |
66 | $z = $r->new($proper_int); | |
c32198f6 | 67 | is ($z,$proper2); |
7d341013 T |
68 | |
69 | $z = $r->new($proper_float); | |
c32198f6 | 70 | is ($z,$proper2); |
7d341013 T |
71 | |
72 | ############################################################################## | |
73 | # bdiv | |
74 | ||
75 | $x = $r->new('12345678901234567890'); $y = Math::BigRat->new('2'); | |
76 | $z = $x->copy->bdiv($y); | |
c32198f6 | 77 | is ($z,$proper); |
7d341013 T |
78 | |
79 | ############################################################################## | |
80 | # bmul | |
81 | ||
82 | $x = $r->new("$proper"); $y = Math::BigRat->new('1'); | |
83 | $z = $x->copy->bmul($y); | |
c32198f6 | 84 | is ($z,$proper); |
7d341013 T |
85 | |
86 | $x = $r->new("$proper"); $y = Math::BigRat->new('2'); | |
87 | $z = $x->copy->bmul($y); | |
c32198f6 | 88 | is ($z,$proper2); |
7d341013 T |
89 | |
90 | ############################################################################## | |
12fc2493 | 91 | # binc/bdec |
7d341013 | 92 | |
c32198f6 FR |
93 | $x = $proper->copy()->binc(); is ($x,$proper_inc); |
94 | $x = $proper->copy()->bdec(); is ($x,$proper_dec); | |
7d341013 | 95 |