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