develooper Front page | perl.perl5.porters | Postings from November 2000

looks_like_number (was Re: SvOOK_on)

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
November 26, 2000 14:36
Subject:
looks_like_number (was Re: SvOOK_on)
Message ID:
20001126223557.A50556@plum.flirble.org
> Jarkko Hietaniemi <jhi@iki.fi> writes:

> >Okay, I must be blind.  But I blame the whoever it was who wrote
> >sv_chop() for not using SvOOK_on(sv) :-)

ah, yes. I grepped for SvOOK_on (and didn't notice anything interesting
about SVf_OOK being on the right of an = sign


sv.c says:

    /*
     * we return IS_NUMBER_TO_INT_BY_ATOL if the number can be converted
     * to _integer_ with atol() and IS_NUMBER_TO_INT_BY_ATOF if you need
     * (int)atof().
     */


I can't think any situation where (int)atof() would give you an answer
better than atol() for a number matching /[-+]?[0-9]+/

[currently looks_like_number returns either just IS_NUMBER_TO_INT_BY_ATOL
or IS_NUMBER_TO_INT_BY_ATOF | IS_NUMBER_NOT_IV]

Am I missing something obscure (or obvious)? If you know that the string
you're converting to the number is an integer (possibly greater than
the largest int) why use (int)atof() at all, as atol() returns LONG_MAX
on overflow, which is what we want the cast to do.

[forgive my/that comment's lax terminology. s/int/long/g; and I think there
are no problems when sizeof(int) != sizeof(long)]

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