{{ message }}

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

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

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

opened this issue Apr 15, 2014 · 6 comments
Labels

### p5pRT commented Apr 15, 2014

 Migrated from rt.perl.org#121668 (status was 'resolved') Searchable as RT121668\$

### 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.

### 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 ++--
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();
}
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
index 318deb6..5516fa7 100644
@@ -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

```

### 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 commented Apr 15, 2014

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

### 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 commented May 29, 2014

 @tonycoz - Status changed from 'open' to 'resolved'
closed this May 29, 2014
added the label Oct 19, 2019