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