Subject: | nearest() gives NaN for input and rounding that are not NaN - interaction with Math::BigRat |
Hi, I have used the module Math::BigRat, which is a core Perl module since perl 5.8.0, to store a rational number and then convert it to floating point. But then Math::Round::nearest behaves oddly with the resulting scalar.
use Math::BigRat;
use Math::Round qw(nearest);
my $x = new Math::BigRat(1);
$x = $x->as_float;
print $x, "\n";
print nearest(0.0001, $x), "\n";
print nearest(0.00001, $x), "\n";
For me this prints
1
0
NaN
So we have what looks like an ordinary number 1, which is rounded correctly when you give a target rounding of 0.0001, but strangely gives NaN if the target is 0.00001.
This is perl 5, version 22, subversion 1 (v5.22.1) built for x86_64-linux-thread-multi
(with 14 registered patches, see perl -V for more detail)
(Perl packaged by Fedora 23 x86_64)