develooper Front page | perl.perl5.porters | Postings from May 2001

Re: [ID 20010529.006] String plus zero inconsistent across platforms

Thread Previous | Thread Next
From:
Robert Spier
Date:
May 31, 2001 11:15
Subject:
Re: [ID 20010529.006] String plus zero inconsistent across platforms
Message ID:
15126.35315.554250.110467@rls.cx

Jarkko Hietaniemi writes:
>> I don't think we do: for a long time we have taught people that "37xa"
>> numifies to 37, and I think it is unreasonable and unhelpful now to
>> change "0xa" to numify to something other than 0. I think your example
>> should numify to 0 + 10 + 0 = 10.
>
>Well, in that case we must go in the other direction and stop some
>Atof()s from numifying "0xa" to 10.

I agree with Hugo, but the portability problem remains.

Might something that does something similar to:

    sub Atof {
	my $_ = shift;
	s/^\s*(\d+(?:\.\d+)).*$/$1/;
	# $_ is now _only_ digits.
	return strtod($_);
    }

be a happy solution?

-R

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