Skip Menu |

This queue is for tickets about the Number-Format CPAN distribution.

Report information
The Basics
Id: 40126
Status: resolved
Priority: 0/
Queue: Number-Format

People
Owner: WRW [...] cpan.org
Requestors: cameron.mellor [...] jpmorgan.com
Cc:
AdminCc:

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



Subject: format_number(97, 20) -> 96?!!
Date: Fri, 17 Oct 2008 10:50:45 +0100
To: bug-Number-Format [...] rt.cpan.org
From: cameron.mellor [...] jpmorgan.com
u068928@mfnppb104:~> /apps/perl/5.8.8/bin/perl -e 'use Number::Format qw(:subs); print format_number(97, 20), "\n";' 96 I believe it goes wrong in round(), which converts 97 to 96.99999...., and then format_number() uses int() on the result giving the problem: u068928@mfnppb104:~> /apps/perl/5.8.8/bin/perl -e 'use Number::Format qw(:subs); printf("%.25f\n", 97);' 97.0000000000000000000000000 u068928@mfnppb104:~> /apps/perl/5.8.8/bin/perl -e 'use Number::Format qw(:subs); printf("%.25f\n", round(97,20));' 96.9999999999999857891452848 Thanks, Cameron Generally, this communication is for informational purposes only and it is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. In the event you are receiving the offering materials attached below related to your interest in hedge funds or private equity, this communication may be intended as an offer or solicitation for the purchase or sale of such fund(s). All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to UK legal entities.
Subject: format_number(97, 20) -> 96?!! - Version info, etc.
From: cameron.mellor [...] jpmorgan.com
On Fri Oct 17 05:53:23 2008, cameron.mellor@jpmorgan.com wrote: Show quoted text
> u068928@mfnppb104:~> /apps/perl/5.8.8/bin/perl -e 'use
Number::Format Show quoted text
> qw(:subs); print format_number(97, 20), "\n";' > 96
Version info: Perl 5.8.8 N::F 1.52 (but I checked: it's a problem in 1.60) OS Solaris 8 Cameron
Subject: Re: [rt.cpan.org #40126] format_number(97, 20) -> 96?!!
Date: Fri, 17 Oct 2008 11:45:11 -0700
To: bug-Number-Format [...] rt.cpan.org
From: "Bill Ward" <bill [...] wards.net>
Well, precision of 20 is more than your computer can actually handle in a floating point number. I'll see if maybe we can throw an error if you try to do that. On Fri, Oct 17, 2008 at 2:53 AM, cameron.mellor@jpmorgan.com via RT < bug-Number-Format@rt.cpan.org> wrote: Show quoted text
> Fri Oct 17 05:53:23 2008: Request 40126 was acted upon. > Transaction: Ticket created by cameron.mellor@jpmorgan.com > Queue: Number-Format > Subject: format_number(97, 20) -> 96?!! > Broken in: (no value) > Severity: (no value) > Owner: Nobody > Requestors: cameron.mellor@jpmorgan.com > Status: new > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=40126 > > > > u068928@mfnppb104:~> /apps/perl/5.8.8/bin/perl -e 'use Number::Format > qw(:subs); print format_number(97, 20), "\n";' > 96 > > I believe it goes wrong in round(), which converts 97 to 96.99999...., and > then format_number() uses int() on the result giving the problem: > > u068928@mfnppb104:~> /apps/perl/5.8.8/bin/perl -e 'use Number::Format > qw(:subs); printf("%.25f\n", 97);' > 97.0000000000000000000000000 > u068928@mfnppb104:~> /apps/perl/5.8.8/bin/perl -e 'use Number::Format > qw(:subs); printf("%.25f\n", round(97,20));' > 96.9999999999999857891452848 > > Thanks, > > Cameron > > Generally, this communication is for informational purposes only > and it is not intended as an offer or solicitation for the purchase > or sale of any financial instrument or as an official confirmation > of any transaction. In the event you are receiving the offering > materials attached below related to your interest in hedge funds or > private equity, this communication may be intended as an offer or > solicitation for the purchase or sale of such fund(s). All market > prices, data and other information are not warranted as to > completeness or accuracy and are subject to change without notice. > Any comments or statements made herein do not necessarily reflect > those of JPMorgan Chase & Co., its subsidiaries and affiliates. > > This transmission may contain information that is privileged, > confidential, legally privileged, and/or exempt from disclosure > under applicable law. If you are not the intended recipient, you > are hereby notified that any disclosure, copying, distribution, or > use of the information contained herein (including any reliance > thereon) is STRICTLY PROHIBITED. Although this transmission and any > attachments are believed to be free of any virus or other defect > that might affect any computer system into which it is received and > opened, it is the responsibility of the recipient to ensure that it > is virus free and no responsibility is accepted by JPMorgan Chase & > Co., its subsidiaries and affiliates, as applicable, for any loss > or damage arising in any way from its use. If you received this > transmission in error, please immediately contact the sender and > destroy the material in its entirety, whether in electronic or hard > copy format. Thank you. > Please refer to http://www.jpmorgan.com/pages/disclosures for > disclosures relating to UK legal entities. > >
10**20 is larger than Perl can accurately store in a variable, thus the inaccuracy. The limit is 2**53. Added an error case in round() which will detect the overflow, and added a test case based on this bug. It will be available in the next release of Number::Format.
Fixed in release 1.72