Upgrade to Math::BigInt 1.56, Math::BigRat 0.05,
[p5sagit/p5-mst-13.2.git] / t / lib / Math / BigInt / Subclass.pm
1 #!/usr/bin/perl -w
2
3 package Math::BigInt::Subclass;
4
5 require 5.005_02;
6 use strict;
7
8 use Exporter;
9 use Math::BigInt(1.56);
10 use vars qw($VERSION @ISA $PACKAGE @EXPORT_OK
11             $accuracy $precision $round_mode $div_scale);
12
13 @ISA = qw(Exporter Math::BigInt);
14 @EXPORT_OK = qw(bgcd objectify);
15
16 $VERSION = 0.03;
17
18 use overload;   # inherit overload from BigInt
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
30         my $value       = shift;
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;
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
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
63 sub import
64   {
65   my $self = shift;
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 ?
79   }
80
81 1;