This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update bignum to CPAN version 0.44
[perl5.git] / cpan / bignum / lib / Math / BigFloat / Trace.pm
1 #!perl
2
3 package Math::BigFloat::Trace;
4
5 require 5.006;
6 use strict;
7 use warnings;
8
9 use Exporter;
10 use Math::BigFloat;
11
12 our ($PACKAGE, @EXPORT_OK, $accuracy, $precision, $round_mode, $div_scale);
13
14 our @ISA = qw(Exporter Math::BigFloat);
15
16 our $VERSION = '0.44';
17
18 use overload;                   # inherit overload from BigFloat
19
20 # Globals
21 $accuracy = $precision = undef;
22 $round_mode = 'even';
23 $div_scale = 40;
24
25 sub new {
26     my $proto = shift;
27     my $class = ref($proto) || $proto;
28
29     my $value = shift;
30     my $a = $accuracy;
31     $a = $_[0] if defined $_[0];
32     my $p = $precision;
33     $p = $_[1] if defined $_[1];
34     my $self = Math::BigFloat->new($value, $a, $p, $round_mode);
35
36     # remember, downgrading may return a BigInt, so don't meddle with class
37     # bless $self, $class;
38
39     print "MBF new '$value' => '$self' (", ref($self), ")";
40     return $self;
41 }
42
43 sub import {
44     print "MBF import ", join(' ', @_);
45     my $self = shift;
46
47     # we catch the constants, the rest goes go BigFloat
48     my @a = ();
49     foreach (@_) {
50         push @a, $_ if $_ ne ':constant';
51     }
52     overload::constant float => sub { $self->new(shift); };
53
54     Math::BigFloat->import(@a);                 # need it for subclasses
55 #    $self->export_to_level(1,$self,@_);         # need this ?
56 }
57
58 1;