Number-WithError
view release on metacpan or search on metacpan
lib/Number/WithError.pm view on Meta::CPAN
my $class = ref($proto)||$proto;
# clone
if (ref($proto) and not @_) {
my $num = $proto->{num};
$num = $num->copy() if ref($num);
my $err = [];
foreach (@{$proto->{errors}}) {
push @$err, ref($_) eq 'ARRAY' ? [map {ref($_) ? $_->copy() : $_} @$_] : (ref($_) ? $_->copy() : $_)
}
return bless {num => $num, errors => $err} => $class;
}
return undef if not @_;
my $num = shift;
return undef if not defined $num;
if (not @_) {
return _parse_string($num, $class);
}
my $errors = [];
my $self = {
num => $num,
errors => $errors,
};
bless $self => $class;
while (@_) {
my $err = shift;
if (_ARRAY($err)) {
if (@$err == 1) {
push @$errors, CORE::abs($err->[0] || 0);
}
else {
push @$errors, [CORE::abs($err->[0] || 0), CORE::abs($err->[1] || 0)];
lib/Number/WithError.pm view on Meta::CPAN
elsif ($str =~ / \G \s* \+ \s* ($CFloat) \s* \- \s* ($CFloat)/cgxo) {
push @$err, [CORE::abs($1), CORE::abs($2)];
}
elsif ($str =~ /\G \s* \- \s* ($CFloat) \s* \+ \s* ($CFloat)/cgxo) {
push @$err, [CORE::abs($2), CORE::abs($1)];
}
else {
last;
}
}
return bless { num => $num, errors => $err } => $class;
}
=head2 new_big
This is an alternative constructor for C<Number::WithError>
objects. It works exactly like C<new> except that it makes all
internal numbers instances of C<Math::BigFloat> for high precision
calculations.
The module does not load C<Math::BigFloat> at compile time to avoid
( run in 0.305 second using v1.01-cache-2.11-cpan-65fba6d93b7 )