Commit | Line | Data |
ee15d750 |
1 | #!/usr/bin/perl -w |
2 | |
b68b7ab1 |
3 | # for testing subclassing Math::BigFloat |
4 | |
dccbb853 |
5 | package Math::BigFloat::Subclass; |
ee15d750 |
6 | |
7 | require 5.005_02; |
8 | use strict; |
9 | |
10 | use Exporter; |
990fb837 |
11 | use Math::BigFloat(1.38); |
dccbb853 |
12 | use vars qw($VERSION @ISA $PACKAGE |
ee15d750 |
13 | $accuracy $precision $round_mode $div_scale); |
14 | |
15 | @ISA = qw(Exporter Math::BigFloat); |
16 | |
b68b7ab1 |
17 | $VERSION = 0.05; |
b3abae2a |
18 | |
19 | use overload; # inherit overload from BigInt |
ee15d750 |
20 | |
21 | # Globals |
22 | $accuracy = $precision = undef; |
23 | $round_mode = 'even'; |
24 | $div_scale = 40; |
25 | |
26 | sub new |
27 | { |
28 | my $proto = shift; |
29 | my $class = ref($proto) || $proto; |
30 | |
394e6ffb |
31 | my $value = shift; |
61f5c3f5 |
32 | my $a = $accuracy; $a = $_[0] if defined $_[0]; |
33 | my $p = $precision; $p = $_[1] if defined $_[1]; |
ee15d750 |
34 | # Store the floating point value |
61f5c3f5 |
35 | my $self = Math::BigFloat->new($value,$a,$p,$round_mode); |
36 | bless $self, $class; |
ee15d750 |
37 | $self->{'_custom'} = 1; # make sure this never goes away |
38 | return $self; |
39 | } |
40 | |
13a12e00 |
41 | BEGIN |
42 | { |
43 | *objectify = \&Math::BigInt::objectify; |
b68b7ab1 |
44 | # to allow Math::BigFloat::Subclass::bgcd( ... ) style calls |
45 | *bgcd = \&Math::BigFloat::bgcd; |
46 | *blcm = \&Math::BigFloat::blcm; |
13a12e00 |
47 | } |
48 | |
ee15d750 |
49 | 1; |