1 package Math::BigRat::Test;
9 use vars qw($VERSION @ISA
10 $accuracy $precision $round_mode $div_scale);
12 @ISA = qw(Math::BigRat Exporter);
15 use overload; # inherit overload from BigRat
18 $accuracy = $precision = undef;
22 my $class = 'Math::BigRat::Test';
27 # my $class = ref($proto) || $proto;
30 # my $a = $accuracy; $a = $_[0] if defined $_[0];
31 # my $p = $precision; $p = $_[1] if defined $_[1];
32 # # Store the floating point value
33 # my $self = Math::BigFloat->new($value,$a,$p,$round_mode);
34 # bless $self, $class;
35 # $self->{'_custom'} = 1; # make sure this never goes away
43 *objectify = \&Math::BigInt::objectify;
44 *AUTOLOAD = \&Math::BigRat::AUTOLOAD;
46 foreach my $method ( qw/ div acmp floor ceil root sqrt log fac modpow modinv/)
48 *{'b' . $method} = \&{'Math::BigRat::b' . $method};
56 #print "$a $accuracy $precision $round_mode\n";
57 Math::BigFloat->round_mode($round_mode);
58 Math::BigFloat->accuracy($a || $accuracy);
59 Math::BigFloat->precision(undef);
60 my $y = Math::BigFloat->new($x->bsstr(),undef,undef);
61 $class->new($y->fround($a));
68 Math::BigFloat->round_mode($round_mode);
69 Math::BigFloat->accuracy(undef);
70 Math::BigFloat->precision($p || $precision);
71 my $y = Math::BigFloat->new($x->bsstr(),undef,undef);
72 $class->new($y->ffround($p));
77 # calculate a BigFloat compatible string output
80 $x = $class->new($x) unless ref $x;
82 if ($x->{sign} !~ /^[+-]$/) # inf, NaN etc
84 my $s = $x->{sign}; $s =~ s/^\+//; # +inf => inf
88 my $s = ''; $s = $x->{sign} if $x->{sign} ne '+'; # +3 vs 3
90 # print " bstr \$x ", $accuracy || $x->{_a} || 'notset', " ", $precision || $x->{_p} || 'notset', "\n";
91 return $s.$x->{_n} if $x->{_d}->is_one();
92 my $output = Math::BigFloat->new($x->{_n})->bdiv($x->{_d});
93 local $Math::BigFloat::accuracy = $accuracy || $x->{_a};
94 local $Math::BigFloat::precision = $precision || $x->{_p};
105 # calculate a BigFloat compatible string output
108 $x = $class->new($x) unless ref $x;
110 if ($x->{sign} !~ /^[+-]$/) # inf, NaN etc
112 my $s = $x->{sign}; $s =~ s/^\+//; # +inf => inf
116 my $s = ''; $s = $x->{sign} if $x->{sign} ne '+'; # +3 vs 3
118 my $output = Math::BigFloat->new($x->{_n})->bdiv($x->{_d});
119 return $s.$output->bsstr();