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

People
Owner: Nobody in particular
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

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



From gg [...] zip.com.au Tue Feb 11 17: 15:00 2014
MIME-Version: 1.0
X-Spam-Status: No, score=-1.9 tagged_above=-99.9 required=10 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=ham
X-Spam-Flag: NO
content-type: text/plain; charset="utf-8"
Message-ID: <8738jp1emu.fsf [...] blah.blah>
X-Virus-Scanned: Debian amavisd-new at bestpractical.com
X-Spam-Score: -1.9
Received: from localhost (localhost [127.0.0.1]) by hipster.bestpractical.com (Postfix) with ESMTP id 86919240E2A for <cpan-bug+Math-BigInt [...] hipster.bestpractical.com>; Tue, 11 Feb 2014 17:15:00 -0500 (EST)
Received: from hipster.bestpractical.com ([127.0.0.1]) by localhost (hipster.bestpractical.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SJuZIKdMipve for <cpan-bug+Math-BigInt [...] hipster.bestpractical.com>; Tue, 11 Feb 2014 17:14:59 -0500 (EST)
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by hipster.bestpractical.com (Postfix) with SMTP id B474E240A5A for <bug-Math-BigInt [...] rt.cpan.org>; Tue, 11 Feb 2014 17:14:57 -0500 (EST)
Received: (qmail 2134 invoked by alias); 11 Feb 2014 22:14:57 -0000
Received: from mailout2-15.pacific.net.au (HELO mailout4-syd3.pacific.net.au) (125.255.80.142) by la.mx.develooper.com (qpsmtpd/0.28) with ESMTP; Tue, 11 Feb 2014 14:14:55 -0800
Received: from mailproxy3-syd3.pacific.net.au (mailproxy3-syd3.pacific.net.au [61.8.2.164]) by mailout4-syd3.pacific.net.au (Postfix) with ESMTP id B75F1A1F56 for <bug-Math-BigInt [...] rt.cpan.org>; Wed, 12 Feb 2014 09:14:49 +1100 (EST)
Received: from blah.blah (unknown [203.26.175.139]) by mailproxy3-syd3.pacific.net.au (Postfix) with ESMTP id 51F61578085 for <bug-Math-BigInt [...] rt.cpan.org>; Wed, 12 Feb 2014 09:14:49 +1100 (EST)
Received: from gg by blah.blah with local (Exim 4.82) (envelope-from <gg [...] blah.blah>) id 1WDLab-0001Tg-Px for bug-Math-BigInt [...] rt.cpan.org; Wed, 12 Feb 2014 09:14:01 +1100
Delivered-To: cpan-bug+Math-BigInt [...] hipster.bestpractical.com
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)
Subject: BigFloat bmod on negative dividend
Return-Path: <gg [...] zip.com.au>
X-RT-Mail-Extension: math-bigint
X-Original-To: cpan-bug+Math-BigInt [...] hipster.bestpractical.com
X-Spam-Check-BY: la.mx.develooper.com
Date: Wed, 12 Feb 2014 09:14:01 +1100
X-Spam-Level:
To: bug-Math-BigInt [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
X-RT-Original-Encoding: ascii
X-RT-Interface: Email
Content-Length: 378
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.
MIME-Version: 1.0
In-Reply-To: <8738jp1emu.fsf [...] blah.blah>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <8738jp1emu.fsf [...] blah.blah>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-6903-1392243285-10.92953-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 937
Download (untitled) / with headers
text/plain 937b
Comparing BigInt.pm and BigFloat.pm, 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.
MIME-Version: 1.0
In-Reply-To: <8738jp1emu.fsf [...] blah.blah>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <8738jp1emu.fsf [...] blah.blah>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-17698-1442322509-1589.92953-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 28
Fixed in Math-BigInt-1.9994.


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

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.