develooper Front page | perl.perl5.porters | Postings from March 2007

Re: [perl #41645] NaNcytyping appears to have regressed and broken again in 5.8.8

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
March 1, 2007 04:45
Subject:
Re: [perl #41645] NaNcytyping appears to have regressed and broken again in 5.8.8
Message ID:
20070301124507.GR5748@plum.flirble.org
On Wed, Feb 28, 2007 at 09:22:28PM -0800, Michael G Schwern wrote:
> Yitzchak Scott-Thoennes wrote:
> > To me, 0+"Nancy" being NaN is consistent with how numeric values are treated
> > in general; it's not much different from 0+"123beer" being 123.
> 
> Interpreting "123beer" as 123 is already pretty desperate but at least
> understandable.  Interpreting "Nancy" as NaN is well gone.  And of course
> "Infant" is inf.  About the only reasonable special case of this sort of
> thing is "Infinity".
> 
> At least they warn.

I thought that the have /\A-?inf(?:inity)?\z/i as the valid ways of spelling
infinity. I can't remember whether NaN is allowed to be /\Anan\z/i or if
it's also acceptable to say /\Anan\(.*\)\z/i

I *think* that all this broke between 5.6.x and 5.8.0, in that in 5.6.x
platforms where atof() recognised those strings got those values, and
everyone else got 0.0

I don't have a machine with 5.6.x where 'NaN' is NaN, but I tried this
test program

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv) {
  while (*++argv) {
    double f = atof(*argv);
    printf("'%s' is %g\n", *argv, f);
  }
  return 0;
}


on FreeBSD, Linux and Solaris and the results are, well, not what I'd hoped
for:

$ ./atof 42 infinity nan nancy NaN infinite infinitesimal -inFerior
'42' is 42
'infinity' is inf
'nan' is nan
'nancy' is nan
'NaN' is nan
'infinite' is inf
'infinitesimal' is inf
'-inFerior' is -inf

$ ./atof 42 infinity nan nancy NaN infinite infinitesimal -inFerior
'42' is 42
'infinity' is inf
'nan' is nan
'nancy' is nan
'NaN' is nan
'infinite' is inf
'infinitesimal' is inf
'-inFerior' is -inf

$ ./atof 42 infinity nan nancy NaN infinite infinitesimal -inFerior
'42' is 42
'infinity' is Inf
'nan' is NaN
'nancy' is NaN
'NaN' is NaN
'infinite' is Inf
'infinitesimal' is Inf
'-inFerior' is -Inf


(and not what I thought happened when I chatted to Jesse about this on IRC)


Well, at least Solaris still is C, rather than C99:

$ ./atof 0x3 0x3p2
'0x3' is 3
'0x3p2' is 12
$ uname
Linux

$ ./atof 0x3 0x3p2
'0x3' is 3
'0x3p2' is 12
$ uname
FreeBSD

$ ./atof 0x3 0x3p2
'0x3' is 0
'0x3p2' is 0
$ uname 
SunOS


It was that bit of C99 stupidity that prompted this whole issue, IIRC.

You thought long long was bad - wait until you realise that they changed the
documented behaviour of a library function without changing the name. Your
libc can't be both C89 and C99 conformant.

Nicholas Clark

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About