xref: /openbsd-src/gnu/usr.bin/perl/cpan/Math-BigInt/t/Math/BigFloat/Subclass.pm (revision 898184e3e61f9129feb5978fad5a8c6865f00b92)
1#!/usr/bin/perl -w
2
3# for testing subclassing Math::BigFloat
4
5package Math::BigFloat::Subclass;
6
7require 5.005_02;
8use strict;
9
10use Exporter;
11use Math::BigFloat(1.38);
12use vars qw($VERSION @ISA $PACKAGE
13            $accuracy $precision $round_mode $div_scale);
14
15@ISA = qw(Exporter Math::BigFloat);
16
17$VERSION = 0.05;
18
19use overload; 		# inherit overload from BigInt
20
21# Globals
22$accuracy = $precision = undef;
23$round_mode = 'even';
24$div_scale = 40;
25
26sub new
27{
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        # Store the floating point value
35        my $self = Math::BigFloat->new($value,$a,$p,$round_mode);
36        bless $self, $class;
37        $self->{'_custom'} = 1; # make sure this never goes away
38        return $self;
39}
40
41BEGIN
42  {
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