# is_numeric_string and general string-to-number conversion

- Thread: https://externals.io/message/25113
- Original archive: https://news-web.php.net/php.internals/25113
- Started by Matt W on 2006-08-02T10:45:36+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #25113 — Matt W — 2006-08-02T10:45:36+00:00

URL: https://externals.io/message/25113#25113

Hi there,

I've been looking at the different string->number related functions lately.
It looks like is_numeric_[string|unicode]() could be optimized.  Here's what
I was thinking: Can functions like zend_[string|unicode]_to_number() be
added?  Then is_numeric_* could always call only 1 function that would
handle long and double (like in _php_math_basetozval). Now strtol() or
zend_strtod() can be called unnecessarily, depending on the scenario.

BUT, in order for me to do this, *can* doubles/floats be handled
correctly/accurately using simple code such as in the existing
zend_string_to_double()?  So you know what I mean, the function prototype
might look like this:

zend_uchar zend_string_to_number(char *str, char **end, int base, long
*lval, double *dval)

This is the type of function I think would be nice (on its own) where I was
updating PHP's dec*() functions to handle larger values -- 
is_numeric_string/convert_scalar_to_number aren't right, IMO, because they
allow hex strings (in `dechex()`?? :-)), besides being more inefficient
because of the current is_numeric_string.  I was looking for more of a plain
convert_to_number, like convert_to_long, but would use a double if needed.

Thoughts?


Thanks,
Matt
