Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] Fix bug in Math::BigFloat's bceil() and bint() methods. #14679

Closed
p5pRT opened this issue Apr 28, 2015 · 8 comments
Closed

[PATCH] Fix bug in Math::BigFloat's bceil() and bint() methods. #14679

p5pRT opened this issue Apr 28, 2015 · 8 comments

Comments

@p5pRT
Copy link

p5pRT commented Apr 28, 2015

Migrated from rt.perl.org#124412 (status was 'resolved')

Searchable as RT124412$

@p5pRT
Copy link
Author

p5pRT commented Apr 28, 2015

From @pjacklam

Fix bug in Math​::BigFloat's bceil() and bint() methods.

- When $x is a Math​::BigFloat, $x -> bceil() and $x -> bint() for -1 < $x < 0
  returns -0. Negative zero is never used by Math​::Big(Int|Float), and care has
  been taken to avoid it, so this bug is surely an oversight.

- This patch fixes CPAN RT #104012.

@p5pRT
Copy link
Author

p5pRT commented Apr 28, 2015

From @pjacklam

0001-Fix-bug-in-Math-BigFloat-s-bceil-and-bint-methods.patch
From ce8d0076e0d44b0614e37883c8db9cc2fad33b6f Mon Sep 17 00:00:00 2001
From: Peter John Acklam <pjacklam@online.no>
Date: Tue, 28 Apr 2015 13:07:43 +0200
Subject: [PATCH] Fix bug in Math::BigFloat's bceil() and bint() methods.

- When $x is a Math::BigFloat, $x -> bceil() and $x -> bint() for -1 < $x < 0
  returns -0. Negative zero is never used by Math::Big(Int|Float), and care has
  been taken to avoid it, so this bug is surely an oversight.

- This patch fixes CPAN RT #104012.
---
 dist/Math-BigInt/lib/Math/BigFloat.pm | 7 ++++++-
 dist/Math-BigInt/t/bare_mbf.t         | 2 +-
 dist/Math-BigInt/t/bigfltpm.inc       | 2 ++
 dist/Math-BigInt/t/bigfltpm.t         | 2 +-
 dist/Math-BigInt/t/sub_mbf.t          | 2 +-
 dist/Math-BigInt/t/with_sub.t         | 2 +-
 6 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/dist/Math-BigInt/lib/Math/BigFloat.pm b/dist/Math-BigInt/lib/Math/BigFloat.pm
index 2f5753f..a423b35 100644
--- a/dist/Math-BigInt/lib/Math/BigFloat.pm
+++ b/dist/Math-BigInt/lib/Math/BigFloat.pm
@@ -3528,7 +3528,11 @@ sub bceil
     $x->{_m} = $MBI->_rsft($x->{_m},$x->{_e},10); # cut off digits after dot
     $x->{_e} = $MBI->_zero();			# trunc/norm	
     $x->{_es} = '+';				# abs e
-    $MBI->_inc($x->{_m}) if $x->{sign} eq '+';	# increment if positive
+    if ($x->{sign} eq '+') {
+        $MBI->_inc($x->{_m});                   # increment if positive
+    } else {
+        $x->{sign} = '+' if $MBI->_is_zero($x->{_m});   # avoid -0
+    }
     }
   $x->round($a,$p,$r);
   }
@@ -3547,6 +3551,7 @@ sub bint
     $x->{_m} = $MBI->_rsft($x->{_m},$x->{_e},10); # cut off digits after dot
     $x->{_e} = $MBI->_zero();                     # truncate/normalize
     $x->{_es} = '+';                              # abs e
+    $x->{sign} = '+' if $MBI->_is_zero($x->{_m}); # avoid -0
     }
   $x->round($a,$p,$r);
   }
diff --git a/dist/Math-BigInt/t/bare_mbf.t b/dist/Math-BigInt/t/bare_mbf.t
index 8f37270..69dcc80 100644
--- a/dist/Math-BigInt/t/bare_mbf.t
+++ b/dist/Math-BigInt/t/bare_mbf.t
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 use strict;
-use Test::More tests => 2336;
+use Test::More tests => 2340;
 
 BEGIN { unshift @INC, 't'; }
 
diff --git a/dist/Math-BigInt/t/bigfltpm.inc b/dist/Math-BigInt/t/bigfltpm.inc
index 2ffeafa..3eb2e21 100644
--- a/dist/Math-BigInt/t/bigfltpm.inc
+++ b/dist/Math-BigInt/t/bigfltpm.inc
@@ -1823,6 +1823,7 @@ abc:NaN
 -51:-51
 -51.2:-51
 12.2:13
+-0.4:0
 &fint
 0:0
 NaN:NaN
@@ -1832,3 +1833,4 @@ NaN:NaN
 -51:-51
 -51.2:-51
 12.2:12
+-0.4:0
diff --git a/dist/Math-BigInt/t/bigfltpm.t b/dist/Math-BigInt/t/bigfltpm.t
index 6f6e598..8653f77 100644
--- a/dist/Math-BigInt/t/bigfltpm.t
+++ b/dist/Math-BigInt/t/bigfltpm.t
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 use strict;
-use Test::More tests => 2336
+use Test::More tests => 2340
     + 5;		# own tests
 
 
diff --git a/dist/Math-BigInt/t/sub_mbf.t b/dist/Math-BigInt/t/sub_mbf.t
index 28252b4..fec4d07 100644
--- a/dist/Math-BigInt/t/sub_mbf.t
+++ b/dist/Math-BigInt/t/sub_mbf.t
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 use strict;
-use Test::More tests => 2336
+use Test::More tests => 2340
     + 6;	# + our own tests
 
 
diff --git a/dist/Math-BigInt/t/with_sub.t b/dist/Math-BigInt/t/with_sub.t
index 48dfa30..d90bbbc 100644
--- a/dist/Math-BigInt/t/with_sub.t
+++ b/dist/Math-BigInt/t/with_sub.t
@@ -3,7 +3,7 @@
 # Test use Math::BigFloat with => 'Math::BigInt::SomeSubclass';
 
 use strict;
-use Test::More tests => 2336 + 1;
+use Test::More tests => 2340 + 1;
 
 use Math::BigFloat with => 'Math::BigInt::Subclass', lib => 'Calc';
 
-- 
2.1.4

@p5pRT
Copy link
Author

p5pRT commented Jun 2, 2015

From @tonycoz

On Tue Apr 28 04​:12​:24 2015, pjacklam wrote​:

Fix bug in Math​::BigFloat's bceil() and bint() methods.

- When $x is a Math​::BigFloat, $x -> bceil() and $x -> bint() for -1 <
$x < 0
returns -0. Negative zero is never used by Math​::Big(Int|Float), and
care has
been taken to avoid it, so this bug is surely an oversight.

- This patch fixes CPAN RT #104012.

Thanks, applied to blead as 669bc51.

Tony

@p5pRT
Copy link
Author

p5pRT commented Jun 2, 2015

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jun 2, 2015

@tonycoz - Status changed from 'open' to 'resolved'

@p5pRT
Copy link
Author

p5pRT commented Jun 4, 2015

@tonycoz - Status changed from 'resolved' to 'pending release'

@p5pRT
Copy link
Author

p5pRT commented May 13, 2016

From @khwilliamson

Thank you for submitting this report. You have helped make Perl better.
 
With the release of Perl 5.24.0 on May 9, 2016, this and 149 other issues have been resolved.

Perl 5.24.0 may be downloaded via https://metacpan.org/release/RJBS/perl-5.24.0

@p5pRT
Copy link
Author

p5pRT commented May 13, 2016

@khwilliamson - Status changed from 'pending release' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant