1# -*- mode: perl; -*- 2 3# for testing subclassing Math::BigFloat 4 5package Math::BigFloat::Subclass; 6 7require 5.006; 8 9use strict; 10use warnings; 11 12use Exporter; 13use Math::BigFloat; 14 15our @ISA = qw(Math::BigFloat Exporter); 16 17our $VERSION = "0.08"; 18 19use overload; # inherit overload from BigInt 20 21# Globals 22our $accuracy = undef; 23our $precision = undef; 24our $round_mode = Math::BigFloat::Subclass -> round_mode(); 25our $div_scale = Math::BigFloat::Subclass -> div_scale(); 26our $lib = ''; 27 28sub new { 29 my $proto = shift; 30 my $class = ref($proto) || $proto; 31 32 my $value = shift; 33 my $a = $accuracy; $a = $_[0] if defined $_[0]; 34 my $p = $precision; $p = $_[1] if defined $_[1]; 35 # Store the floating point value 36 my $self = Math::BigFloat->new($value, $a, $p, $round_mode); 37 bless $self, $class; 38 $self->{'_custom'} = 1; # make sure this never goes away 39 return $self; 40} 41 42BEGIN { 43 *objectify = \&Math::BigInt::objectify; 44 # to allow Math::BigFloat::Subclass::bgcd( ... ) style calls 45 *bgcd = \&Math::BigFloat::bgcd; 46 *blcm = \&Math::BigFloat::blcm; 47} 48 491; 50