On Mon, Jun 21, 2004 at 10:11:49PM -0500, Eric Wilhelm wrote:
> # The following was supposedly scribed by
> # Steve Grazzini
> # on Monday 21 June 2004 08:53 pm:
> 
> >I believe this is because 5.6 used the C library atof() but more
> >recent perls provide their own portable implementation. �Or maybe
> >the internal atof() didn't used to be the default, but now it is.

This is correct. I didn't like that change at the time and should have said
so.

> I suppose I'm probably better off that way, since the perl 5.6 behavior wasn't 
> documented as such, so I'm not sure if it would have worked that way on other 
> platforms.

atof is platform dependant

/usr/bin/perl -le '$a = Inf; $a+= 0; print "$^O $] $a"'
linux 5.006001 inf
/usr/bin/perl -le '$a = Inf; $a+= 0; print "$^O $] $a"'
freebsd 5.006001 0


And the change was because atof was broken by the C99 standard. (Fuckwits)

C89 standard says that atof of "0x3" is 0.0, C99 says that "0x3" is
treated as a hex floating point constant.

Hence


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

int main() {
  const char *foo = "0x3";
  printf("'%s' is %g\n", foo, atof(foo));
  return 0;
}


on a newer system with a C99 libc gives:

'0x3' is 3

whereas an old system with a C89 libc gives:

'0x3' is 0


A competent standard would have defined a function with a new name for the
new behaviour.

Nicholas Clark

Reply via email to