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 RT #62052: Math::BigFloat -> bdiv() in list context #13738

Closed
p5pRT opened this issue Apr 15, 2014 · 6 comments
Closed

[PATCH] Fix RT #62052: Math::BigFloat -> bdiv() in list context #13738

p5pRT opened this issue Apr 15, 2014 · 6 comments
Labels

Comments

@p5pRT
Copy link
Collaborator

@p5pRT p5pRT commented Apr 15, 2014

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

Searchable as RT121668$

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Apr 15, 2014

From @pjacklam

Fix RT #62052​: Math​::BigFloat -> bdiv() in list context

In list context, Math​::BigFloat -> bdiv() returns the quotient and remainder.
By convention, this means that the quotient and remainder, q and r, after
dividing x by y, satisfies x = q*y + r. The current behaviour is to return x/y
and r, which do not satisfy this relation, and - more importantly - is not what
people expect.

dist/Math-BigInt/lib/Math/BigFloat.pm​: Patched to fix this bug.

t/bigfltpm.inc and t/upgrade.inc​: Fixed test cases to match the new behaviour.

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Apr 15, 2014

From @pjacklam

0001-Fix-RT-62052-Math-BigFloat-bdiv-in-list-context.patch
From be301d08cac86cfc69ed7e5c535a74e7f55930f5 Mon Sep 17 00:00:00 2001
From: pjacklam <pjacklam@online.no>
Date: Tue, 15 Apr 2014 23:03:18 +0200
Subject: [PATCH] Fix RT #62052: Math::BigFloat -> bdiv() in list context

In list context, Math::BigFloat -> bdiv() returns the quotient and remainder.
By convention, this means that the quotient and remainder, q and r, after
dividing x by y, satisfies x = q*y + r. The current behaviour is to return x/y
and r, which do not satisfy this relation, and - more importantly - is not what
people expect.

dist/Math-BigInt/lib/Math/BigFloat.pm: Patched to fix this bug.

t/bigfltpm.inc and t/upgrade.inc: Fixed test cases to match the new behaviour.
---
 dist/Math-BigInt/lib/Math/BigFloat.pm |    1 +
 dist/Math-BigInt/t/bigfltpm.inc       |    4 ++--
 dist/Math-BigInt/t/upgrade.inc        |   14 +++++++-------
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/dist/Math-BigInt/lib/Math/BigFloat.pm b/dist/Math-BigInt/lib/Math/BigFloat.pm
index fb1d206..0486e4f 100644
--- a/dist/Math-BigInt/lib/Math/BigFloat.pm
+++ b/dist/Math-BigInt/lib/Math/BigFloat.pm
@@ -1895,6 +1895,7 @@ sub bdiv
     {
     if ($y_not_one)
       {
+      $x -> bint();
       $rem->bmod($y,@params);			# copy already done
       }
     if ($fallback)
diff --git a/dist/Math-BigInt/t/bigfltpm.inc b/dist/Math-BigInt/t/bigfltpm.inc
index 0911627..1528e48 100644
--- a/dist/Math-BigInt/t/bigfltpm.inc
+++ b/dist/Math-BigInt/t/bigfltpm.inc
@@ -1406,8 +1406,8 @@ NaNmul:-inf:NaN
 &fdiv-list
 0:0:NaN,NaN
 0:1:0,0
-9:4:2.25,1
-9:5:1.8,4
+9:4:2,1
+9:5:1,4
 # bug in v1.74 with bdiv in list context, when $y is 1 or -1
 2.1:-1:-2.1,0
 2.1:1:2.1,0
diff --git a/dist/Math-BigInt/t/upgrade.inc b/dist/Math-BigInt/t/upgrade.inc
index 318deb6..5516fa7 100644
--- a/dist/Math-BigInt/t/upgrade.inc
+++ b/dist/Math-BigInt/t/upgrade.inc
@@ -834,15 +834,15 @@ NaNmul:-inf:NaN
 -4095:-4095:1,0
 4095:-4095:-1,0
 -4095:4095:-1,0
-123:2:61.5,1
-9:5:1.8,4
-9:4:2.25,1
+123:2:61,1
+9:5:1,4
+9:4:2,1
 # inf handling and general remainder
-5:8:0.625,5
+5:8:0,5
 0:8:0,0
-11:2:5.5,1
-11:-2:-5.5,-1
--11:2:-5.5,1
+11:2:5,1
+11:-2:-5,-1
+-11:2:-5,1
 # see table in documentation in MBI
 0:inf:0,0
 0:-inf:0,0
-- 
1.7.9

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Apr 15, 2014

From @tonycoz

On Tue Apr 15 14​:12​:23 2014, pjacklam wrote​:

Fix RT #62052​: Math​::BigFloat -> bdiv() in list context

In list context, Math​::BigFloat -> bdiv() returns the quotient and
remainder.
By convention, this means that the quotient and remainder, q and r,
after
dividing x by y, satisfies x = q*y + r. The current behaviour is to
return x/y
and r, which do not satisfy this relation, and - more importantly - is
not what
people expect.

dist/Math-BigInt/lib/Math/BigFloat.pm​: Patched to fix this bug.

t/bigfltpm.inc and t/upgrade.inc​: Fixed test cases to match the new
behaviour.

Thanks, I'll apply this after 5.20 is released.

Tony

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Apr 15, 2014

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

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented May 29, 2014

From @tonycoz

On Tue Apr 15 14​:12​:23 2014, pjacklam wrote​:

Fix RT #62052​: Math​::BigFloat -> bdiv() in list context

In list context, Math​::BigFloat -> bdiv() returns the quotient and
remainder.
By convention, this means that the quotient and remainder, q and r,
after
dividing x by y, satisfies x = q*y + r. The current behaviour is to
return x/y
and r, which do not satisfy this relation, and - more importantly - is
not what
people expect.

dist/Math-BigInt/lib/Math/BigFloat.pm​: Patched to fix this bug.

t/bigfltpm.inc and t/upgrade.inc​: Fixed test cases to match the new
behaviour.

Thanks, applied as 32f4893.

Tony

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented May 29, 2014

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

@p5pRT p5pRT closed this May 29, 2014
@p5pRT p5pRT added the Severity Low label Oct 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.