3 package Math::BigRat::Test;
11 use vars qw($VERSION @ISA $PACKAGE
12 $accuracy $precision $round_mode $div_scale);
14 @ISA = qw(Exporter Math::BigRat);
17 use overload; # inherit overload from BigRat
20 $accuracy = $precision = undef;
24 my $class = 'Math::BigRat::Test';
29 # my $class = ref($proto) || $proto;
32 # my $a = $accuracy; $a = $_[0] if defined $_[0];
33 # my $p = $precision; $p = $_[1] if defined $_[1];
34 # # Store the floating point value
35 # my $self = Math::BigFloat->new($value,$a,$p,$round_mode);
36 # bless $self, $class;
37 # $self->{'_custom'} = 1; # make sure this never goes away
43 # calculate a BigFloat compatible string output
46 $x = $class->new($x) unless ref $x;
48 if ($x->{sign} !~ /^[+-]$/) # inf, NaN etc
50 my $s = $x->{sign}; $s =~ s/^\+//; # +inf => inf
54 my $s = ''; $s = $x->{sign} if $x->{sign} ne '+'; # +3 vs 3
56 return $s.$x->{_n} if $x->{_d}->is_one();
57 my $output = Math::BigFloat->new($x->{_n})->bdiv($x->{_d});
58 return $s.$output->bstr();
63 # calculate a BigFloat compatible string output
66 $x = $class->new($x) unless ref $x;
68 if ($x->{sign} !~ /^[+-]$/) # inf, NaN etc
70 my $s = $x->{sign}; $s =~ s/^\+//; # +inf => inf
74 my $s = ''; $s = $x->{sign} if $x->{sign} ne '+'; # +3 vs 3
76 return $s.$x->{_n}->bsstr() if $x->{_d}->is_one();
77 my $output = Math::BigFloat->new($x->{_n})->bdiv($x->{_d});
78 return $s.$output->bsstr();