Subject: | In some situations, new() ignores caller-specified P |
Date: | Sun, 23 Jul 2017 09:21:00 -0600 |
To: | bug-Math-BigFloat [...] rt.cpan.org |
From: | Glenn Golden <gdg [...] zplane.com> |
This seemingly straighforward BigFloat creation
$y = Math::BigFloat->new($x, undef, P); # P is an arbitrary integer
seems to ignore P if $x is an extant BigFloat that already has a P value.
The resulting P of $y is always the same as the P of $x. Minimal demo
script below. List of loaded modules (via perldebug 'M') attached.
This was surprising to me. Didn't see anything in the doc that might account
for this behavior, but perhaps I missed it. Is it intentional? If so, please
explain rationale.
Thanks!
======================== begin inline script =============================
#!/usr/bin/perl
#
# Minimal example showing that BigFloat->new() can sometimes create
# variables that are slightly used or "pre-owned".
#
use strict;
use warnings FATAL => 'all';
use Math::BigFloat;
print "Perl version $^V\n";
print "Math::BigFloat version $Math::BigFloat::VERSION\n";
#
# Create $x using new(), specifying P = -10.
#
my $x = Math::BigFloat->new("1234.56789", undef, -10);
print "P(x): " . ($x->precision() // 'undef') . "\n";
#
# Create $y using new(), specifying $x as the value, and specifying P = -23.
# Result is unexpected (to me): No matter what value is supplied for P when
# creating $y, the reported precision of $y is the same as the precision of $x.
#
my $y = Math::BigFloat->new($x, undef, -23);
print "P(y): " . ($y->precision() // 'undef') . "\n";
======================== end inline script =============================
Message body is not shown because sender requested not to inline it.