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
sprintf %f panics with NaN #9027
Comments
From zefram@fysh.orgCreated by zefram@fysh.orgOn NetBSD, frexp() produces silly results if given a NaN argument. START_PATCH Inline Patch--- sv.c.orig 2006-08-15 13:37:41.000000000 +0100
+++ sv.c 2007-09-11 23:09:09.555166783 +0100
@@ -9138,7 +9138,7 @@
: SvNVx(argsv);
need = 0;
- if (c != 'e' && c != 'E') {
+ if (c != 'e' && c != 'E' && nv == nv) {
i = PERL_INT_MIN;
/* FIXME: if HAS_LONG_DOUBLE but not USE_LONG_DOUBLE this
will cast our (long double) to (double) */
This problem came up in CPAN testers reports on one of my modules. Perl Info
|
From @TuxOn Tue, 11 Sep 2007 15:22:23 -0700, Zefram (via RT)
From my C-knowledge point of view, I completely fail to see the effect It is like writing if (1 == 1) {
-- |
The RT System itself - Status changed from 'new' to 'open' |
From @nwc10On Wed, Sep 12, 2007 at 08:50:30AM +0000, H.Merijn Brand wrote:
We'd better call you icc then. :-( NaN != NaN Nicholas Clark |
From @TuxOn Wed, 12 Sep 2007 09:53:08 +0100, Nicholas Clark <nick@ccl4.org> wrote:
tux will do
/me realizes again that he is never too old to learn new tricks -- |
From david@cantrell.org.ukOn Tue, Sep 11, 2007 at 03:22:23PM -0700, Zefram wrote:
'Twas I who generated the original bug report. I'm downloading blead as -- The voices said it's a good day to clean my weapons |
From @rgsOn 12/09/2007, via RT Zefram <perlbug-followup@perl.org> wrote:
now successfully tested. Thanks, applied as #31854. |
From @demerphqOn 9/12/07, Rafael Garcia-Suarez <rgarciasuarez@gmail.com> wrote:
Is it worth tweaking this to explain the point of the nv==nv check? yves |
From @rgsOn 12/09/2007, Rafael Garcia-Suarez <rgarciasuarez@gmail.com> wrote:
Further amended like this: Change 31855 by rgs@stcosmo on 2007/09/12 11:48:32 Amend change 31854 for when NAN_COMPARE_BROKEN Affected files ... ... //depot/perl/sv.c#1423 edit Differences ... ==== //depot/perl/sv.c#1423 (text) ==== @@ -9194,7 +9194,12 @@ need = 0; |
From perl5-porters@perl.orgOn Tue, Sep 11, 2007 at 03:22:23PM -0700, Zefram wrote:
This is only a partial fix. The affected module gets a little bit t/class_all..........ok 1/35panic: frexp at t/class_all.t line 9, <DATA> -- Just because it is possible to do this sort of thing |
From zefram@fysh.orgDavid Cantrell wrote:
Is that, by any chance, failing on an infinity? Try this test: perl -we 'printf "%f\n", 2**1e100' and for good measure: perl -we 'printf "%f\n", -2**1e100' If that's the problem, infinities will have to be detected in the sprintf -zefram |
From david@cantrell.org.ukOn Wed, Sep 12, 2007 at 04:57:17PM +0100, Zefram wrote:
Yup $ .../perl-5.10.0/bin/perl -we 'printf "%f\n", 2**1e100'
Same again -- I remember when computers were frustrating because they did |
From @nwc10On Wed, Sep 12, 2007 at 04:57:17PM +0100, Zefram wrote:
Given the spec in: http://www.opengroup.org/pubs/online/7908799/xsh/frexp.html perl is being buggy for not checking for NaN, +Inf or -Inf, because the Given this: $ perl -wle 'print 0 * "nan"' (and a non-broken nan comparison) it seems to be fairly easy to check for Nicholas Clark |
From @nwc10On Wed, Sep 12, 2007 at 06:20:48PM +0100, Nicholas Clark wrote:
And the converse is that 0 * anything else is 0, which is easier to check for, Nicholas Clark Change 31856 by nicholas@nicholas-saigo on 2007/09/12 18:38:54 Don't call frexp() on +Inf or -Inf either. (It's not just NaN it might Affected files ... ... //depot/perl/sv.c#1424 edit Differences ... ==== //depot/perl/sv.c#1424 (text) ==== @@ -9194,12 +9194,9 @@ need = 0; |
From @nwc10On Wed, Sep 12, 2007 at 07:40:08PM +0100, Nicholas Clark wrote:
I'm not sure how (or where) to write good regression tests for this, that don't Nicholas Clark |
From zefram@fysh.orgNicholas Clark wrote:
You don't need to know whether NaNs and infinities actually exist. use Test::More; -zefram |
From david@cantrell.org.ukOn Wed, Sep 12, 2007 at 07:40:08PM +0100, Nicholas Clark wrote:
Which works, for both NaNs and Infs, on NetBSD 2.1.0_STABLE/alpha at -- "Cynical" is a word used by the naive to describe the experienced. |
From p5p@spam.wizbit.beSmall history of the ticket: $ perl -we 'printf "%f\n", Inf/-Inf/Nan' (This was fixed by changes: 31855, 31856) On Wed Sep 12 13:59:27 2007, zefram@fysh.org wrote:
I checked t/op/sprintf.t <http://public.activestate.com/cgi-bin/ Were they added elsewhere? Or were there any problems with the test Kind regards, Bram |
From zefram@fysh.orgBram via RT wrote:
As far as I know, no one got around to it. My mail records don't include -zefram |
p5p@spam.wizbit.be - Status changed from 'open' to 'resolved' |
From p5p@perl.wizbit.beQuoting Zefram <zefram@fysh.org>:
Patch attached. Kind regards, Bram |
From p5p@perl.wizbit.beInline Patch--- old/t/op/sprintf2.t 2008-04-28 20:34:08.000000000 +0200
+++ new/t/op/sprintf2.t 2008-04-29 22:22:54.000000000 +0200
@@ -6,7 +6,7 @@
require './test.pl';
}
-plan tests => 1292;
+plan tests => 1295;
is(
sprintf("%.40g ",0.01),
@@ -134,3 +134,9 @@
}
}
+
+# test that %f doesn't panic with +Inf, -Inf, NaN [perl #45383]
+foreach my $n (2**1e100, -2**1e100, 2**1e100/2**1e100) { # +Inf, -Inf, NaN
+ eval { my $f = sprintf("%f", $n); };
+ is $@, "", "sprintf(\"%f\", $n)";
+} |
From @rgsThanks, applied. 2008/4/29 Bram <p5p@perl.wizbit.be>:
|
Migrated from rt.perl.org#45383 (status was 'resolved')
Searchable as RT45383$
The text was updated successfully, but these errors were encountered: