This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade Math::BigRat from version 0.25 to 0.26
[perl5.git] / cpan / Math-BigRat / t / big_ap.t
CommitLineData
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 6use strict;
c32198f6 7use Test::More tests => 17;
7d341013
T
8
9use Math::BigInt;
10use Math::BigFloat;
11use Math::BigRat;
12
13my $r = 'Math::BigRat';
14my $proper = $r->new('12345678901234567890/2');
15my $proper_inc = $r->new('12345678901234567890/2')->binc();
16my $proper_dec = $r->new('12345678901234567890/2')->bdec();
17my $proper_int = Math::BigInt->new('12345678901234567890');
18my $proper_float = Math::BigFloat->new('12345678901234567890');
19my $proper2 = $r->new('12345678901234567890');
20
21print "# Start\n";
22
23Math::BigInt->accuracy(3);
24Math::BigFloat->accuracy(5);
25
26my ($x,$y,$z);
27
28##############################################################################
29# new()
30
31$z = $r->new('12345678901234567890/2');
c32198f6 32is ($z,$proper);
7d341013
T
33
34$z = $r->new('1234567890123456789E1');
c32198f6 35is ($z,$proper2);
7d341013
T
36
37$z = $r->new('12345678901234567890/1E0');
c32198f6 38is ($z,$proper2);
7d341013 39$z = $r->new('1234567890123456789e1/1');
c32198f6 40is ($z,$proper2);
7d341013 41$z = $r->new('1234567890123456789e1/1E0');
c32198f6 42is ($z,$proper2);
7d341013
T
43
44$z = $r->new($proper_int);
c32198f6 45is ($z,$proper2);
7d341013
T
46
47$z = $r->new($proper_float);
c32198f6 48is ($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 55is ($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 62is ($z,$proper);
7d341013 63$z = $r->new('12345678901234567890/1E0');
c32198f6 64is ($z,$proper2);
7d341013
T
65
66$z = $r->new($proper_int);
c32198f6 67is ($z,$proper2);
7d341013
T
68
69$z = $r->new($proper_float);
c32198f6 70is ($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 77is ($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 84is ($z,$proper);
7d341013
T
85
86$x = $r->new("$proper"); $y = Math::BigRat->new('2');
87$z = $x->copy->bmul($y);
c32198f6 88is ($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