1N/Apackage Math::BigRat::Test;
1N/A
1N/Arequire 5.005_02;
1N/Ause strict;
1N/A
1N/Ause Exporter;
1N/Ause Math::BigRat;
1N/Ause Math::BigFloat;
1N/Ause vars qw($VERSION @ISA
1N/A $accuracy $precision $round_mode $div_scale);
1N/A
1N/A@ISA = qw(Math::BigRat Exporter);
1N/A$VERSION = 0.04;
1N/A
1N/Ause overload; # inherit overload from BigRat
1N/A
1N/A# Globals
1N/A$accuracy = $precision = undef;
1N/A$round_mode = 'even';
1N/A$div_scale = 40;
1N/A
1N/Amy $class = 'Math::BigRat::Test';
1N/A
1N/A#ub new
1N/A#{
1N/A# my $proto = shift;
1N/A# my $class = ref($proto) || $proto;
1N/A#
1N/A# my $value = shift;
1N/A# my $a = $accuracy; $a = $_[0] if defined $_[0];
1N/A# my $p = $precision; $p = $_[1] if defined $_[1];
1N/A# # Store the floating point value
1N/A# my $self = Math::BigFloat->new($value,$a,$p,$round_mode);
1N/A# bless $self, $class;
1N/A# $self->{'_custom'} = 1; # make sure this never goes away
1N/A# return $self;
1N/A#}
1N/A
1N/ABEGIN
1N/A {
1N/A *fstr = \&bstr;
1N/A *fsstr = \&bsstr;
1N/A *objectify = \&Math::BigInt::objectify;
1N/A *AUTOLOAD = \&Math::BigRat::AUTOLOAD;
1N/A no strict 'refs';
1N/A foreach my $method ( qw/ div acmp floor ceil root sqrt log fac modpow modinv/)
1N/A {
1N/A *{'b' . $method} = \&{'Math::BigRat::b' . $method};
1N/A }
1N/A }
1N/A
1N/Asub fround
1N/A {
1N/A my ($x,$a) = @_;
1N/A
1N/A #print "$a $accuracy $precision $round_mode\n";
1N/A Math::BigFloat->round_mode($round_mode);
1N/A Math::BigFloat->accuracy($a || $accuracy);
1N/A Math::BigFloat->precision(undef);
1N/A my $y = Math::BigFloat->new($x->bsstr(),undef,undef);
1N/A $class->new($y->fround($a));
1N/A }
1N/A
1N/Asub ffround
1N/A {
1N/A my ($x,$p) = @_;
1N/A
1N/A Math::BigFloat->round_mode($round_mode);
1N/A Math::BigFloat->accuracy(undef);
1N/A Math::BigFloat->precision($p || $precision);
1N/A my $y = Math::BigFloat->new($x->bsstr(),undef,undef);
1N/A $class->new($y->ffround($p));
1N/A }
1N/A
1N/Asub bstr
1N/A {
1N/A # calculate a BigFloat compatible string output
1N/A my ($x) = @_;
1N/A
1N/A $x = $class->new($x) unless ref $x;
1N/A
1N/A if ($x->{sign} !~ /^[+-]$/) # inf, NaN etc
1N/A {
1N/A my $s = $x->{sign}; $s =~ s/^\+//; # +inf => inf
1N/A return $s;
1N/A }
1N/A
1N/A my $s = ''; $s = $x->{sign} if $x->{sign} ne '+'; # +3 vs 3
1N/A
1N/A# print " bstr \$x ", $accuracy || $x->{_a} || 'notset', " ", $precision || $x->{_p} || 'notset', "\n";
1N/A return $s.$x->{_n} if $x->{_d}->is_one();
1N/A my $output = Math::BigFloat->new($x->{_n})->bdiv($x->{_d});
1N/A local $Math::BigFloat::accuracy = $accuracy || $x->{_a};
1N/A local $Math::BigFloat::precision = $precision || $x->{_p};
1N/A $s.$output->bstr();
1N/A }
1N/A
1N/Asub numify
1N/A {
1N/A $_[0]->bsstr();
1N/A }
1N/A
1N/Asub bsstr
1N/A {
1N/A # calculate a BigFloat compatible string output
1N/A my ($x) = @_;
1N/A
1N/A $x = $class->new($x) unless ref $x;
1N/A
1N/A if ($x->{sign} !~ /^[+-]$/) # inf, NaN etc
1N/A {
1N/A my $s = $x->{sign}; $s =~ s/^\+//; # +inf => inf
1N/A return $s;
1N/A }
1N/A
1N/A my $s = ''; $s = $x->{sign} if $x->{sign} ne '+'; # +3 vs 3
1N/A
1N/A my $output = Math::BigFloat->new($x->{_n})->bdiv($x->{_d});
1N/A return $s.$output->bsstr();
1N/A }
1N/A
1N/A1;