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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
# -*- mode: perl; -*-
# Test that accuracy() and precision() in BigInt/BigFloat do not disturb
# the rounding force in BigRat.
use strict;
use warnings;
use Test::More tests => 17;
use Math::BigInt;
use Math::BigFloat;
use Math::BigRat;
my $proper = Math::BigRat -> new('12345678901234567890/2');
my $proper_inc = Math::BigRat -> new('12345678901234567890/2') -> binc();
my $proper_dec = Math::BigRat -> new('12345678901234567890/2') -> bdec();
my $proper_int = Math::BigInt -> new('12345678901234567890');
my $proper_float = Math::BigFloat -> new('12345678901234567890');
my $proper2 = Math::BigRat -> new('12345678901234567890');
Math::BigInt -> accuracy(3);
Math::BigFloat -> accuracy(5);
my ($x, $y, $z);
##############################################################################
# new()
note "Test new()";
$z = Math::BigRat->new("12345678901234567890/2");
is($z, $proper, q|Math::BigRat->new("12345678901234567890/2")|);
$z = Math::BigRat->new("1234567890123456789E1");
is($z, $proper2, q|Math::BigRat->new("1234567890123456789E1")|);
$z = Math::BigRat->new("12345678901234567890/1E0");
is($z, $proper2, q|Math::BigRat->new("12345678901234567890/1E0")|);
$z = Math::BigRat->new("1234567890123456789e1/1");
is($z, $proper2, q|Math::BigRat->new("1234567890123456789e1/1")|);
$z = Math::BigRat->new("1234567890123456789e1/1E0");
is($z, $proper2, q|Math::BigRat->new("1234567890123456789e1/1E0")|);
$z = Math::BigRat->new($proper_int);
is($z, $proper2, qq|Math::BigRat->new("$proper_int")|);
$z = Math::BigRat->new($proper_float);
is($z, $proper2, qq|Math::BigRat->new("$proper_float")|);
##############################################################################
# bdiv
note "Test bdiv()";
$x = Math::BigRat->new("12345678901234567890");
$y = Math::BigRat->new("2");
$z = $x->copy->bdiv($y);
is($z, $proper);
##############################################################################
# bmul
note "Test bmul()";
$x = Math::BigRat->new("$proper");
$y = Math::BigRat->new("1");
$z = $x->copy->bmul($y);
is($z, $proper);
$z = Math::BigRat->new("12345678901234567890/1E0");
is($z, $proper2);
$z = Math::BigRat->new($proper_int);
is($z, $proper2);
$z = Math::BigRat->new($proper_float);
is($z, $proper2);
##############################################################################
# bdiv
note "Test bdiv()";
$x = Math::BigRat->new("12345678901234567890");
$y = Math::BigRat->new("2");
$z = $x->copy->bdiv($y);
is($z, $proper);
##############################################################################
# bmul
note "Test bmul()";
$x = Math::BigRat->new("$proper");
$y = Math::BigRat->new("1");
$z = $x->copy->bmul($y);
is($z, $proper);
$x = Math::BigRat->new("$proper");
$y = Math::BigRat->new("2");
$z = $x->copy->bmul($y);
is($z, $proper2);
##############################################################################
# binc
note "Test binc()";
$x = $proper->copy()->binc();
is($x, $proper_inc);
##############################################################################
# binc
note "Test bdec()";
$x = $proper->copy()->bdec();
is($x, $proper_dec);
|