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] Speed up Math::BigFloat -> blog(). #14671

Closed
p5pRT opened this issue Apr 24, 2015 · 10 comments
Closed

[PATCH] Speed up Math::BigFloat -> blog(). #14671

p5pRT opened this issue Apr 24, 2015 · 10 comments
Labels

Comments

@p5pRT
Copy link
Collaborator

@p5pRT p5pRT commented Apr 24, 2015

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

Searchable as RT124382$

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Apr 24, 2015

From @pjacklam

Speed up Math​::BigFloat -> blog().

- Intermediate computations in blog() increases the number of digits
  significantly in some cases. Reduce the number of digits by rounding.
  However, keep some extra digits for remaining intermediate computations
  before the final rounding.

- This patch fixes CPAN RT #43924.

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Apr 24, 2015

From @pjacklam

0001-Speed-up-Math-BigFloat-blog.patch
From a6be9fcc4d8599540a1ec04fd04f8d9d0672cad0 Mon Sep 17 00:00:00 2001
From: Peter John Acklam <pjacklam@online.no>
Date: Fri, 24 Apr 2015 15:13:33 +0200
Subject: [PATCH] Speed up Math::BigFloat -> blog().

- Intermediate computations in blog() increases the number of digits
  significantly in some cases. Reduce the number of digits by rounding.
  However, keep some extra digits for remaining intermediate computations
  before the final rounding.

- This patch fixes CPAN RT #43924.
---
 dist/Math-BigInt/lib/Math/BigFloat.pm | 1 +
 1 file changed, 1 insertion(+)

diff --git a/dist/Math-BigInt/lib/Math/BigFloat.pm b/dist/Math-BigInt/lib/Math/BigFloat.pm
index 1c31496..3c51914 100644
--- a/dist/Math-BigInt/lib/Math/BigFloat.pm
+++ b/dist/Math-BigInt/lib/Math/BigFloat.pm
@@ -1476,6 +1476,7 @@ sub _log_10
     {
     $twos++; $x->bdiv($two,$scale+4);		# keep all digits
     }
+  $x->bround($scale+4);
   # $twos > 0 => did mul 2, < 0 => did div 2 (but we never did both)
   # So calculate correction factor based on ln(2):
   if ($twos != 0)
-- 
2.1.4

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Apr 24, 2015

From @kentfredric

On 25 April 2015 at 01​:16, Peter J. Acklam via RT <perlbug-followup@​perl.org

wrote​:

# New Ticket Created by (Peter J. Acklam)
# Please include the string​: [perl #124382]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=124382 >

Speed up Math​::BigFloat -> blog().

- Intermediate computations in blog() increases the number of digits
significantly in some cases. Reduce the number of digits by rounding.
However, keep some extra digits for remaining intermediate computations
before the final rounding.

- This patch fixes CPAN RT #43924.

From a6be9fcc4d8599540a1ec04fd04f8d9d0672cad0 Mon Sep 17 00​:00​:00 2001
From​: Peter John Acklam <pjacklam@​online.no>
Date​: Fri, 24 Apr 2015 15​:13​:33 +0200
Subject​: [PATCH] Speed up Math​::BigFloat -> blog().

- Intermediate computations in blog() increases the number of digits
significantly in some cases. Reduce the number of digits by rounding.
However, keep some extra digits for remaining intermediate computations
before the final rounding.

- This patch fixes CPAN RT #43924.
---
dist/Math-BigInt/lib/Math/BigFloat.pm | 1 +
1 file changed, 1 insertion(+)

diff --git a/dist/Math-BigInt/lib/Math/BigFloat.pm
b/dist/Math-BigInt/lib/Math/BigFloat.pm
index 1c31496..3c51914 100644
--- a/dist/Math-BigInt/lib/Math/BigFloat.pm
+++ b/dist/Math-BigInt/lib/Math/BigFloat.pm
@​@​ -1476,6 +1476,7 @​@​ sub _log_10
{
$twos++; $x->bdiv($two,$scale+4); # keep all digits
}
+ $x->bround($scale+4);
# $twos > 0 => did mul 2, < 0 => did div 2 (but we never did both)
# So calculate correction factor based on ln(2)​:
if ($twos != 0)
--
2.1.4

Q) Does this affect the overall precision of the floating point math?

I am ignorant of the internals, but that sort of concern seems to be the
sort of thing lay-folk who are simply using the library would care about,
and so I'm just looking for some kind of assurance the rounding is not
*premature* rounding.

--
Kent

*KENTNL* - https://metacpan.org/author/KENTNL

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Apr 24, 2015

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

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Apr 28, 2015

From @pjacklam

Q) Does this affect the overall precision of the floating point math?

I am ignorant of the internals, but that sort of concern seems to be the
sort of thing lay-folk who are simply using the library would care about,
and so I'm just looking for some kind of assurance the rounding is not
*premature* rounding.

The code already rounds to $scale+4 digits, in other cases which involve more intermediate computation, so using four extra digits in this case, should not make things any worse than they already are. I am working on a test program to check blog() more throughly.

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Jun 2, 2015

From @tonycoz

On Fri Apr 24 06​:16​:29 2015, pjacklam wrote​:

Speed up Math​::BigFloat -> blog().

- Intermediate computations in blog() increases the number of digits
significantly in some cases. Reduce the number of digits by rounding.
However, keep some extra digits for remaining intermediate computations
before the final rounding.

- This patch fixes CPAN RT #43924.

Thanks, applied to blead as 0d2463e.

Tony

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Jun 2, 2015

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

@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented Jun 4, 2015

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

@p5pRT
Copy link
Collaborator Author

@p5pRT 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 p5pRT closed this May 13, 2016
@p5pRT
Copy link
Collaborator Author

@p5pRT p5pRT commented May 13, 2016

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

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