1# -*- mode: perl; -*- 2 3package Math::BigInt::Subclass; 4 5require 5.005_02; 6 7use strict; 8use warnings; 9 10use Exporter; 11use Math::BigInt; 12 13our @ISA = qw(Math::BigInt Exporter); 14our @EXPORT_OK = qw(bgcd objectify); 15 16our $VERSION = "0.07"; 17 18use overload; # inherit overload from BigInt 19 20# Globals 21our $accuracy = undef; 22our $precision = undef; 23our $round_mode = Math::BigInt::Subclass -> round_mode(); 24our $div_scale = Math::BigInt::Subclass -> div_scale(); 25our $lib = ''; 26 27sub new { 28 my $proto = shift; 29 my $class = ref($proto) || $proto; 30 31 my $value = shift; 32 my $a = $accuracy; $a = $_[0] if defined $_[0]; 33 my $p = $precision; $p = $_[1] if defined $_[1]; 34 my $self = Math::BigInt->new($value, $a, $p, $round_mode); 35 bless $self, $class; 36 $self->{'_custom'} = 1; # make sure this never goes away 37 return $self; 38} 39 40sub bgcd { 41 Math::BigInt::bgcd(@_); 42} 43 44sub blcm { 45 Math::BigInt::blcm(@_); 46} 47 48sub as_int { 49 Math::BigInt->new($_[0]); 50} 51 52BEGIN { 53 *objectify = \&Math::BigInt::objectify; 54 55 # these are called by AUTOLOAD from BigFloat, so we need at least these. 56 # We cheat, of course.. 57 *bneg = \&Math::BigInt::bneg; 58 *babs = \&Math::BigInt::babs; 59 *bnan = \&Math::BigInt::bnan; 60 *binf = \&Math::BigInt::binf; 61 *bzero = \&Math::BigInt::bzero; 62 *bone = \&Math::BigInt::bone; 63} 64 65sub import { 66 my $self = shift; 67 68 my @a; 69 my $t = 0; 70 foreach (@_) { 71 # remove the "lib => foo" parameters and store it 72 if ($t == 1) { 73 $lib = $_; 74 $t = 0; 75 next; 76 } 77 if ($_ eq 'lib') { 78 $t = 1; 79 next; 80 } 81 push @a, $_; 82 } 83 $self->SUPER::import(@a); # need it for subclasses 84 $self->export_to_level(1, $self, @a); # need this ? 85} 86 871; 88