Hi,

More thoughts...

I forgot to say last time that the manual doesn't mention the dec*()
parameter being treated as unsigned.  The *printf() specifiers b/o/x/X
already do this (although the manual doesn't say that either, only for %u).

After looking through the comments for dechex(), there's another thing: 32-
vs 64-bit.  On a 64-bit system, I think dechex(-123) would currently return
ffffffffffffff85, which when reversed on my system gives

php -d precision=20 -r "var_dump(hexdec('ffffffffffffff85'));"
float(18446744073709552000)

Are you saying, Michael, that the negative behavior should be left as-is for
people to see "how the number is stored by the computer?"  I think just
using the *printf() specifiers would better.  IMO, the dec*() and *dec()
functions should work the same as the corresponding to/from base with
base_convert() (absolute value), and vice-versa.

BTW, can base_convert() simply return an actual number instead of a string
when tobase=10?  Again, to be the same as *dec() and avoid conversion to
string if it's just going to be used in numeric context.


Matt


----- Original Message -----
From: "Michael Wallner"
Sent: Thursday, July 27, 2006


> Matt W wrote:
>
> > That's why I'm assuming negative numbers aren't "really" supported
> > now (not in any form with base_convert()), but it's simply a side
> > effect of wanting to handle *positive* numbers between LONG_MAX and
> > ULONG_MAX.  e.g. when doing dechex(4294967173) that's a PHP double,
> > but it gets converted to long (becomes -123), and finally unsigned
> > long (recovering 4294967173).  IOW, after convert_to_long() in dec*()
> > it doesn't know if -123 or 4294967173 was passed.  Make sense?
> > (Actually, it doesn't, that's my point. :-))
>
> For your computer 0xffffff85 is -123 and 4294967173.  It's just how
> you look on it.
>
> > So after more thinking, I figure when upgrading dec*() to handle any
> > number, absolute value should be used (then int(123) would be
> > returned in my example).  Unless the all the functions are changed to
> > properly accept/return negatives... I personally don't care either
> > way on that.
>
> No way. Why should hexdec(dechex(-123)) return +123?
>
> --
> Michael

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to