1*0Sstevel@tonic-gate#!/usr/bin/perl -w 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gatepackage Math::BigFloat::Trace; 4*0Sstevel@tonic-gate 5*0Sstevel@tonic-gaterequire 5.005_02; 6*0Sstevel@tonic-gateuse strict; 7*0Sstevel@tonic-gate 8*0Sstevel@tonic-gateuse Exporter; 9*0Sstevel@tonic-gateuse Math::BigFloat; 10*0Sstevel@tonic-gateuse vars qw($VERSION @ISA $PACKAGE @EXPORT_OK 11*0Sstevel@tonic-gate $accuracy $precision $round_mode $div_scale); 12*0Sstevel@tonic-gate 13*0Sstevel@tonic-gate@ISA = qw(Exporter Math::BigFloat); 14*0Sstevel@tonic-gate 15*0Sstevel@tonic-gate$VERSION = 0.01; 16*0Sstevel@tonic-gate 17*0Sstevel@tonic-gateuse overload; # inherit overload from BigFloat 18*0Sstevel@tonic-gate 19*0Sstevel@tonic-gate# Globals 20*0Sstevel@tonic-gate$accuracy = $precision = undef; 21*0Sstevel@tonic-gate$round_mode = 'even'; 22*0Sstevel@tonic-gate$div_scale = 40; 23*0Sstevel@tonic-gate 24*0Sstevel@tonic-gatesub new 25*0Sstevel@tonic-gate{ 26*0Sstevel@tonic-gate my $proto = shift; 27*0Sstevel@tonic-gate my $class = ref($proto) || $proto; 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate my $value = shift; 30*0Sstevel@tonic-gate my $a = $accuracy; $a = $_[0] if defined $_[0]; 31*0Sstevel@tonic-gate my $p = $precision; $p = $_[1] if defined $_[1]; 32*0Sstevel@tonic-gate my $self = Math::BigFloat->new($value,$a,$p,$round_mode); 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate# remember, downgrading may return a BigInt, so don't meddle with class 35*0Sstevel@tonic-gate# bless $self,$class; 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate print "MBF new '$value' => '$self' (",ref($self),")"; 38*0Sstevel@tonic-gate return $self; 39*0Sstevel@tonic-gate} 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gatesub import 42*0Sstevel@tonic-gate { 43*0Sstevel@tonic-gate print "MBF import ",join(' ',@_); 44*0Sstevel@tonic-gate my $self = shift; 45*0Sstevel@tonic-gate 46*0Sstevel@tonic-gate # we catch the constants, the rest goes go BigFloat 47*0Sstevel@tonic-gate my @a = (); 48*0Sstevel@tonic-gate foreach (@_) 49*0Sstevel@tonic-gate { 50*0Sstevel@tonic-gate push @a, $_ if $_ ne ':constant'; 51*0Sstevel@tonic-gate } 52*0Sstevel@tonic-gate overload::constant float => sub { $self->new(shift); }; 53*0Sstevel@tonic-gate 54*0Sstevel@tonic-gate Math::BigFloat->import(@a); # need it for subclasses 55*0Sstevel@tonic-gate# $self->export_to_level(1,$self,@_); # need this ? 56*0Sstevel@tonic-gate } 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate1; 59