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

sprintf %f panics with NaN #9027

Closed
p5pRT opened this issue Sep 11, 2007 · 23 comments
Closed

sprintf %f panics with NaN #9027

p5pRT opened this issue Sep 11, 2007 · 23 comments

Comments

@p5pRT
Copy link

p5pRT commented Sep 11, 2007

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

Searchable as RT45383$

@p5pRT
Copy link
Author

p5pRT commented Sep 11, 2007

From zefram@fysh.org

Created by zefram@fysh.org

On NetBSD, frexp() produces silly results if given a NaN argument.
The effect on Perl is that sprintf with "%f" format and a NaN argument
gives the "panic​: frexp" diagnostic. NaN is a special case that doesn't
need any frexp processing. This completely untested patch probably
fixes it.

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) */
END_PATCH

This problem came up in CPAN testers reports on one of my modules.
I don't have a BSD system myself.

Perl Info
(Actually I changed most of what's below this line, to reflect
the perl on which this bug was seen.)


Flags:
    category=core
    severity=medium

Site configuration information for perl v5.9.5:

Summary of my perl5 (revision 5 version 9 subversion 5) configuration:
  Platform:
    osname=netbsd, osvers=2.1.0_stable, archname=alpha-netbsd
    uname='netbsd sdf 2.1.0_stable netbsd 2.1.0_stable (sdf) #0: fri mar 30 02:24:32 utc 2007 root@ol:varsysarchalphacompilesdf alpha '
    config_args='-Dusedevel -Dprefix=/arpa/af/d/drhyde/perl-5.9.5 -de'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -pipe -I/usr/pkg/include',
    optimize='-O',
    cppflags='-fno-strict-aliasing -pipe -I/usr/pkg/include'
    ccversion='', gccversion='3.3.3 (NetBSD nb3 20040520)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -Wl,-rpath,/usr/pkg/lib -Wl,-rpath,/usr/local/lib -L/usr/pkg/lib'
    libpth=/usr/pkg/lib /lib /usr/lib
    libs=-lbind -lgdbm -lm -lcrypt -lutil -lc -lposix
    perllibs=-lbind -lm -lcrypt -lutil -lc -lposix
    libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E '
    cccdlflags='-DPIC -fPIC ', lddlflags='--whole-archive -shared  -L/usr/pkg/lib'

@p5pRT
Copy link
Author

p5pRT commented Sep 12, 2007

From @Tux

On Tue, 11 Sep 2007 15​:22​:23 -0700, Zefram (via RT)
<perlbug-followup@​perl.org> wrote​:

# New Ticket Created by Zefram
# Please include the string​: [perl #45383]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org/rt3/Ticket/Display.html?id=45383 >

This is a bug report for perl from zefram@​fysh.org,
generated with the help of perlbug 1.35 running under perl v5.8.8.

-----------------------------------------------------------------
[Please enter your report here]

On NetBSD, frexp() produces silly results if given a NaN argument.
The effect on Perl is that sprintf with "%f" format and a NaN argument
gives the "panic​: frexp" diagnostic. NaN is a special case that doesn't
need any frexp processing. This completely untested patch probably
fixes it.

START_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) {

From my C-knowledge point of view, I completely fail to see the effect
of this change. If I were the C-optimizer, I'd throw away that part.

It is like writing

  if (1 == 1) {
  ok ("this should always be true");
  }

     i = PERL\_INT\_MIN;
     /\* FIXME&#8203;: if HAS\_LONG\_DOUBLE but not USE\_LONG\_DOUBLE this
        will cast our \(long double\) to \(double\) \*/

END_PATCH

This problem came up in CPAN testers reports on one of my modules.
I don't have a BSD system myself.

[Please do not change anything below this line]
(Actually I changed most of what's below this line, to reflect
the perl on which this bug was seen.)
-----------------------------------------------------------------
---
Flags​:
category=core
severity=medium
---
Site configuration information for perl v5.9.5​:

Summary of my perl5 (revision 5 version 9 subversion 5) configuration​:
Platform​:
osname=netbsd, osvers=2.1.0_stable, archname=alpha-netbsd
uname='netbsd sdf 2.1.0_stable netbsd 2.1.0_stable (sdf) #0​: fri mar 30 02​:24​:32 utc 2007 root@​ol​:varsysarchalphacompilesdf alpha '
config_args='-Dusedevel -Dprefix=/arpa/af/d/drhyde/perl-5.9.5 -de'
hint=recommended, useposix=true, d_sigaction=define
useithreads=undef, usemultiplicity=undef
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler​:
cc='cc', ccflags ='-fno-strict-aliasing -pipe -I/usr/pkg/include',
optimize='-O',
cppflags='-fno-strict-aliasing -pipe -I/usr/pkg/include'
ccversion='', gccversion='3.3.3 (NetBSD nb3 20040520)', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries​:
ld='cc', ldflags =' -Wl,-rpath,/usr/pkg/lib -Wl,-rpath,/usr/local/lib -L/usr/pkg/lib'
libpth=/usr/pkg/lib /lib /usr/lib
libs=-lbind -lgdbm -lm -lcrypt -lutil -lc -lposix
perllibs=-lbind -lm -lcrypt -lutil -lc -lposix
libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version=''
Dynamic Linking​:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E '
cccdlflags='-DPIC -fPIC ', lddlflags='--whole-archive -shared -L/usr/pkg/lib'

--
H.Merijn Brand Amsterdam Perl Mongers (http​://amsterdam.pm.org/)
using & porting perl 5.6.2, 5.8.x, 5.9.x on HP-UX 10.20, 11.00, 11.11,
& 11.23, SuSE 10.0 & 10.2, AIX 4.3 & 5.2, and Cygwin. http​://qa.perl.org
http​://mirrors.develooper.com/hpux/ http​://www.test-smoke.org
  http​://www.goldmark.org/jeff/stupid-disclaimers/

@p5pRT
Copy link
Author

p5pRT commented Sep 12, 2007

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

@p5pRT
Copy link
Author

p5pRT commented Sep 12, 2007

From @nwc10

On Wed, Sep 12, 2007 at 08​:50​:30AM +0000, H.Merijn Brand wrote​:

On Tue, 11 Sep 2007 15​:22​:23 -0700, Zefram (via RT)

- if (c != 'e' && c != 'E') {
+ if (c != 'e' && c != 'E' && nv == nv) {

From my C-knowledge point of view, I completely fail to see the effect
of this change. If I were the C-optimizer, I'd throw away that part.

We'd better call you icc then. :-(

NaN != NaN
It's very strange.

Nicholas Clark

@p5pRT
Copy link
Author

p5pRT commented Sep 12, 2007

From @Tux

On Wed, 12 Sep 2007 09​:53​:08 +0100, Nicholas Clark <nick@​ccl4.org> wrote​:

On Wed, Sep 12, 2007 at 08​:50​:30AM +0000, H.Merijn Brand wrote​:

On Tue, 11 Sep 2007 15​:22​:23 -0700, Zefram (via RT)

- if (c != 'e' && c != 'E') {
+ if (c != 'e' && c != 'E' && nv == nv) {

From my C-knowledge point of view, I completely fail to see the effect
of this change. If I were the C-optimizer, I'd throw away that part.

We'd better call you icc then. :-(

tux will do

NaN != NaN
It's very strange.

/me realizes again that he is never too old to learn new tricks
Thanks for the update

--
H.Merijn Brand Amsterdam Perl Mongers (http​://amsterdam.pm.org/)
using & porting perl 5.6.2, 5.8.x, 5.9.x on HP-UX 10.20, 11.00, 11.11,
& 11.23, SuSE 10.0 & 10.2, AIX 4.3 & 5.2, and Cygwin. http​://qa.perl.org
http​://mirrors.develooper.com/hpux/ http​://www.test-smoke.org
  http​://www.goldmark.org/jeff/stupid-disclaimers/

@p5pRT
Copy link
Author

p5pRT commented Sep 12, 2007

From david@cantrell.org.uk

On Tue, Sep 11, 2007 at 03​:22​:23PM -0700, Zefram wrote​:

On NetBSD, frexp() produces silly results if given a NaN argument.
The effect on Perl is that sprintf with "%f" format and a NaN argument
gives the "panic​: frexp" diagnostic. NaN is a special case that doesn't
need any frexp processing. This completely untested patch probably
fixes it...

This problem came up in CPAN testers reports on one of my modules.
I don't have a BSD system myself.

'Twas I who generated the original bug report. I'm downloading blead as
we speak so I can test Zefram's patch.

--
David Cantrell | London Perl Mongers Deputy Chief Heretic

  The voices said it's a good day to clean my weapons

@p5pRT
Copy link
Author

p5pRT commented Sep 12, 2007

From @rgs

On 12/09/2007, via RT Zefram <perlbug-followup@​perl.org> wrote​:

On NetBSD, frexp() produces silly results if given a NaN argument.
The effect on Perl is that sprintf with "%f" format and a NaN argument
gives the "panic​: frexp" diagnostic. NaN is a special case that doesn't
need any frexp processing. This completely untested patch probably
fixes it.

START_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) */
END_PATCH

now successfully tested. Thanks, applied as #31854.

@p5pRT
Copy link
Author

p5pRT commented Sep 12, 2007

From @demerphq

On 9/12/07, Rafael Garcia-Suarez <rgarciasuarez@​gmail.com> wrote​:

On 12/09/2007, via RT Zefram <perlbug-followup@​perl.org> wrote​:

On NetBSD, frexp() produces silly results if given a NaN argument.
The effect on Perl is that sprintf with "%f" format and a NaN argument
gives the "panic​: frexp" diagnostic. NaN is a special case that doesn't
need any frexp processing. This completely untested patch probably
fixes it.

START_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) */
END_PATCH

now successfully tested. Thanks, applied as #31854.

Is it worth tweaking this to explain the point of the nv==nv check?

yves
--
perl -Mre=debug -e "/just|another|perl|hacker/"

@p5pRT
Copy link
Author

p5pRT commented Sep 12, 2007

From @rgs

On 12/09/2007, Rafael Garcia-Suarez <rgarciasuarez@​gmail.com> wrote​:

now successfully tested. Thanks, applied as #31854.

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 @​@​
  : SvNV(argsv);

  need = 0;
- if (c != 'e' && c != 'E' && nv == nv) {
+#if defined(NAN_COMPARE_BROKEN) && defined(Perl_isnan)
+ if (c != 'e' && c != 'E' && !Perl_isnan(nv))
+#else
+ if (c != 'e' && c != 'E' && nv == nv)
+#endif
+ {
  i = PERL_INT_MIN;
  /* FIXME​: if HAS_LONG_DOUBLE but not USE_LONG_DOUBLE this
  will cast our (long double) to (double) */

@p5pRT
Copy link
Author

p5pRT commented Sep 12, 2007

From perl5-porters@perl.org

On Tue, Sep 11, 2007 at 03​:22​:23PM -0700, Zefram wrote​:

- if (c != 'e' && c != 'E') {
+ if (c != 'e' && c != 'E' && nv == nv) {

This is only a partial fix. The affected module gets a little bit
further along but then does this​:

t/class_all..........ok 1/35panic​: frexp at t/class_all.t line 9, <DATA>
line 1.
# Looks like you planned 35 tests but only ran 15.
# Looks like your test died just after 15.
t/class_all..........dubious
  Test returned status 255 (wstat 65280, 0xff00)
DIED. FAILED tests 16-35
  Failed 20/35 tests, 42.86% okay

--
David Cantrell | Nth greatest programmer in the world

Just because it is possible to do this sort of thing
in the English language doesn't mean it should be done

@p5pRT
Copy link
Author

p5pRT commented Sep 12, 2007

From zefram@fysh.org

David Cantrell wrote​:

This is only a partial fix. The affected module gets a little bit
further along but then does this​:

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
code in the same place that my patch detects NaNs.

-zefram

@p5pRT
Copy link
Author

p5pRT commented Sep 12, 2007

From david@cantrell.org.uk

On Wed, Sep 12, 2007 at 04​:57​:17PM +0100, Zefram wrote​:

Is that, by any chance, failing on an infinity? Try this test​:
perl -we 'printf "%f\n", 2**1e100'

Yup

$ .../perl-5.10.0/bin/perl -we 'printf "%f\n", 2**1e100'
panic​: frexp at -e line 1.

and for good measure​:
perl -we 'printf "%f\n", -2**1e100'

Same again

--
David Cantrell | Official London Perl Mongers Bad Influence

  I remember when computers were frustrating because they did
  exactly what you told them to. That seems kinda quaint now.
  -- JD Baldwin, in the Monastery

@p5pRT
Copy link
Author

p5pRT commented Sep 12, 2007

From @nwc10

On Wed, Sep 12, 2007 at 04​:57​:17PM +0100, Zefram wrote​:

David Cantrell wrote​:

This is only a partial fix. The affected module gets a little bit
further along but then does this​:

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
code in the same place that my patch detects NaNs.

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
behaviour of frexp() with them is partially unspecified.

Given this​:

$ perl -wle 'print 0 * "nan"'
nan
$ perl -wle 'print 0 * "inf"'
nan
$ perl -wle 'print 0 * "-inf"'
nan

(and a non-broken nan comparison) it seems to be fairly easy to check for
these three cases.

Nicholas Clark

@p5pRT
Copy link
Author

p5pRT commented Sep 12, 2007

From @nwc10

On Wed, Sep 12, 2007 at 06​:20​:48PM +0100, Nicholas Clark wrote​:

On Wed, Sep 12, 2007 at 04​:57​:17PM +0100, Zefram wrote​:

If that's the problem, infinities will have to be detected in the sprintf
code in the same place that my patch detects NaNs.

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
behaviour of frexp() with them is partially unspecified.

Given this​:

$ perl -wle 'print 0 * "nan"'
nan
$ perl -wle 'print 0 * "inf"'
nan
$ perl -wle 'print 0 * "-inf"'
nan

(and a non-broken nan comparison) it seems to be fairly easy to check for
these three cases.

And the converse is that 0 * anything else is 0, which is easier to check for,
so I made the appended change

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
  choke on.)

Affected files ...

... //depot/perl/sv.c#1424 edit

Differences ...

==== //depot/perl/sv.c#1424 (text) ====

@​@​ -9194,12 +9194,9 @​@​
  : SvNV(argsv);

  need = 0;
-#if defined(NAN_COMPARE_BROKEN) && defined(Perl_isnan)
- if (c != 'e' && c != 'E' && !Perl_isnan(nv))
-#else
- if (c != 'e' && c != 'E' && nv == nv)
-#endif
- {
+ /* nv * 0 will be NaN for NaN, +Inf and -Inf, and 0 for anything
+ else. frexp() has some unspecified behaviour for those three */
+ if (c != 'e' && c != 'E' && (nv * 0) == 0) {
  i = PERL_INT_MIN;
  /* FIXME​: if HAS_LONG_DOUBLE but not USE_LONG_DOUBLE this
  will cast our (long double) to (double) */

@p5pRT
Copy link
Author

p5pRT commented Sep 12, 2007

From @nwc10

On Wed, Sep 12, 2007 at 07​:40​:08PM +0100, Nicholas Clark wrote​:

On 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,
so I made the appended change

I'm not sure how (or where) to write good regression tests for this, that don't
end up sucking in chunks of Data​::Float.

Nicholas Clark

@p5pRT
Copy link
Author

p5pRT commented Sep 12, 2007

From zefram@fysh.org

Nicholas Clark wrote​:

I'm not sure how (or where) to write good regression tests for this, that don't
end up sucking in chunks of Data​::Float.

You don't need to know whether NaNs and infinities actually exist.
You just need to use formulae that will generate them if they do exist,
and make sure that sprintf doesn't choke on them. How about​:

  use Test​::More;
  foreach(2**1e100, -2**1e100, 2**1e100/2**1e100) {
  eval { sprintf("%f", $_); };
  is $@​, "";
  }

-zefram

@p5pRT
Copy link
Author

p5pRT commented Sep 12, 2007

From david@cantrell.org.uk

On Wed, Sep 12, 2007 at 07​:40​:08PM +0100, Nicholas Clark wrote​:

Change 31856 by nicholas@​nicholas-saigo on 2007/09/12 18​:38​:54

Which works, for both NaNs and Infs, on NetBSD 2.1.0_STABLE/alpha at
least.

--
David Cantrell | Reality Engineer, Ministry of Information

  "Cynical" is a word used by the naive to describe the experienced.
  George Hills, in uknot

@p5pRT
Copy link
Author

p5pRT commented Apr 27, 2008

From p5p@spam.wizbit.be

Small history of the ticket​:

$ perl -we 'printf "%f\n", Inf/-Inf/Nan'
resulted in
panic​: frexp at -e line 1.
(on NetBSD)

(This was fixed by changes​: 31855, 31856)

On Wed Sep 12 13​:59​:27 2007, zefram@​fysh.org wrote​:

Nicholas Clark wrote​:

I'm not sure how (or where) to write good regression tests for this,
that don't
end up sucking in chunks of Data​::Float.

You don't need to know whether NaNs and infinities actually exist.
You just need to use formulae that will generate them if they do
exist,
and make sure that sprintf doesn't choke on them. How about​:

use Test&#8203;::More;
foreach\(2\*\*1e100\, \-2\*\*1e100\, 2\*\*1e100/2\*\*1e100\) \{
    eval \{ sprintf\("%f"\, $\_\); \};
    is $@&#8203;\, "";
\}

-zefram

I checked t/op/sprintf.t <http​://public.activestate.com/cgi-bin/
perlbrowse/l/t/op/sprintf.t> and t/op/sprintf2.t <http​://
public.activestate.com/cgi-bin/perlbrowse/l/t/op/sprintf2.t> to see if
tests for this were added but it appears not.

Were they added elsewhere? Or were there any problems with the test
idea?
Or weren't tests added because of a lack of time/patch?
(If it's the later then I can write a patch)

Kind regards,

Bram

@p5pRT
Copy link
Author

p5pRT commented Apr 27, 2008

From zefram@fysh.org

Bram via RT wrote​:

Were they added elsewhere? Or were there any problems with the test
idea?
Or weren't tests added because of a lack of time/patch?

As far as I know, no one got around to it. My mail records don't include
any reply to the message from me that you quoted. I suggest you make
a patch.

-zefram

@p5pRT
Copy link
Author

p5pRT commented Apr 29, 2008

p5p@spam.wizbit.be - Status changed from 'open' to 'resolved'

@p5pRT p5pRT closed this as completed Apr 29, 2008
@p5pRT
Copy link
Author

p5pRT commented Apr 30, 2008

From p5p@perl.wizbit.be

Quoting Zefram <zefram@​fysh.org>​:

Bram via RT wrote​:

Were they added elsewhere? Or were there any problems with the test
idea?
Or weren't tests added because of a lack of time/patch?

As far as I know, no one got around to it. My mail records don't include
any reply to the message from me that you quoted. I suggest you make
a patch.

-zefram

Patch attached.

Kind regards,

Bram

@p5pRT
Copy link
Author

p5pRT commented Apr 30, 2008

From p5p@perl.wizbit.be

Inline 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)";
+}

@p5pRT
Copy link
Author

p5pRT commented Apr 30, 2008

From @rgs

Thanks, applied.

2008/4/29 Bram <p5p@​perl.wizbit.be>​:

Quoting Zefram <zefram@​fysh.org>​:

Bram via RT wrote​:

Were they added elsewhere? Or were there any problems with the test
idea?
Or weren't tests added because of a lack of time/patch?

As far as I know, no one got around to it. My mail records don't include
any reply to the message from me that you quoted. I suggest you make
a patch.

-zefram

Patch attached.

Kind regards,

Bram

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant