3 # test rounding with non-integer A and P parameters
11 # to locate the testing files
12 my $location = $0; $location =~ s/round.t//i;
15 # testing with the core distribution
18 unshift @INC, qw(../lib);
23 unshift @INC, File::Spec->catdir(File::Spec->updir, $location);
27 unshift @INC, $location;
29 print "# INC = @INC\n";
36 my $cf = 'Math::BigFloat';
37 my $ci = 'Math::BigInt';
39 my $x = $cf->new('123456.123456');
42 _do_a($x, 'round', 3, '123000');
43 _do_a($x, 'bfround', 3, '123500');
44 _do_a($x, 'bfround', 2, '123460');
45 _do_a($x, 'bfround', -2, '123456.12');
46 _do_a($x, 'bfround', -3, '123456.123');
48 _do_a($x, 'bround', 4, '123500');
49 _do_a($x, 'bround', 3, '123000');
50 _do_a($x, 'bround', 2, '120000');
52 _do_a($x, 'bsqrt', 4, '351.4');
53 _do_a($x, 'bsqrt', 3, '351');
54 _do_a($x, 'bsqrt', 2, '350');
57 _do_p($x, 'bsqrt', 2, '350');
58 _do_p($x, 'bsqrt', -2, '351.36');
61 _do_2_a($x, 'bdiv', 2, 6, '61728.1');
62 _do_2_a($x, 'bdiv', 2, 4, '61730');
63 _do_2_a($x, 'bdiv', 2, 3, '61700');
65 _do_2_p($x, 'bdiv', 2, -6, '61728.061728');
66 _do_2_p($x, 'bdiv', 2, -4, '61728.0617');
67 _do_2_p($x, 'bdiv', 2, -3, '61728.062');
71 #############################################################################
75 my ($x, $method, $A, $result) = @_;
77 is ($x->copy->$method($A), $result, "$method($A)");
78 is ($x->copy->$method($A.'.1'), $result, "$method(${A}.1)");
79 is ($x->copy->$method($A.'.5'), $result, "$method(${A}.5)");
80 is ($x->copy->$method($A.'.6'), $result, "$method(${A}.6)");
81 is ($x->copy->$method($A.'.9'), $result, "$method(${A}.9)");
86 my ($x, $method, $P, $result) = @_;
88 is ($x->copy->$method(undef,$P), $result, "$method(undef,$P)");
89 is ($x->copy->$method(undef,$P.'.1'), $result, "$method(undef,${P}.1)");
90 is ($x->copy->$method(undef,$P.'.5'), $result, "$method(undef.${P}.5)");
91 is ($x->copy->$method(undef,$P.'.6'), $result, "$method(undef,${P}.6)");
92 is ($x->copy->$method(undef,$P.'.9'), $result, "$method(undef,${P}.9)");
97 my ($x, $method, $y, $A, $result) = @_;
99 my $cy = $cf->new($y);
101 is ($x->copy->$method($cy,$A), $result, "$method($cy,$A)");
102 is ($x->copy->$method($cy,$A.'.1'), $result, "$method($cy,${A}.1)");
103 is ($x->copy->$method($cy,$A.'.5'), $result, "$method($cy,${A}.5)");
104 is ($x->copy->$method($cy,$A.'.6'), $result, "$method($cy,${A}.6)");
105 is ($x->copy->$method($cy,$A.'.9'), $result, "$method($cy,${A}.9)");
110 my ($x, $method, $y, $P, $result) = @_;
112 my $cy = $cf->new($y);
114 is ($x->copy->$method($cy,undef,$P), $result, "$method(undef,$P)");
115 is ($x->copy->$method($cy,undef,$P.'.1'), $result, "$method($cy,undef,${P}.1)");
116 is ($x->copy->$method($cy,undef,$P.'.5'), $result, "$method($cy,undef.${P}.5)");
117 is ($x->copy->$method($cy,undef,$P.'.6'), $result, "$method($cy,undef,${P}.6)");
118 is ($x->copy->$method($cy,undef,$P.'.9'), $result, "$method($cy,undef,${P}.9)");