Skip Menu |

This queue is for tickets about the Math-BigInt CPAN distribution.

Report information
The Basics
Id: 92953
Status: resolved
Priority: 0/
Queue: Math-BigInt

Owner: Nobody in particular
Requestors: user42 [...]

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 1.9994

Subject: BigFloat bmod on negative dividend
Date: Wed, 12 Feb 2014 09:14:01 +1100
To: bug-Math-BigInt [...]
From: Kevin Ryde <user42 [...]>
Download (untitled) / with headers
text/plain 378b
With recent debian i386 perl 5.18.2 and its included Math::BigFloat 1.998, a program use strict; use Math::BigFloat; my $n = Math::BigFloat->new(-10); my $d = Math::BigFloat->new(5); my $q = $n / $d; my $r = $n % $d; print "n=$n d=$d -> q=$q r=$r\n"; prints n=-10 d=5 -> q=-2 r=5 whereas I expected r=0 since n is exactly divisible by d.
Download (untitled) / with headers
text/plain 937b
Comparing and, it looks like the y-x is supposed to only happen when x != 0. This change to line 1994-2002 at the bottom of bmod seems to work: if ($neg != 0) # one of them negative => correct in place { if (!$MBI->_is_zero($x->{_m})) { my $r = $y - $x; $x->{_m} = $r->{_m}; $x->{_e} = $r->{_e}; $x->{_es} = $r->{_es}; $x->{sign} = '+' if $MBI->_is_zero($x->{_m}); # fix sign for -0 $x->bnorm(); } } The following test failed with the old code, and passes with the new: perl -Iblib/lib -Iblib/arch -MMath::BigInt -MMath::BigFloat -E 'foreach my $x (0 .. 50) { foreach my $y (1 .. 50) { my($fx,$fy,$ix,$iy) = (Math::BigFloat->new(-$x), Math::BigFloat->new($y), Math::BigInt->new(-$x), Math::BigInt->new($y)); my $f = $fx % $fy; my $i = $ix % $iy; die "$ix $iy $f $i\n" unless $f == $i; } }' The standard test suite passes with the patch.
Fixed in Math-BigInt-1.9994.

This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

Please report any issues with to