Re: dec*(), *dec(), base_convert() and negative numbers
| From: | Michael Wallner | Date: | Thu, 27 Jul 2006 13:43:27 +0000 |
| Subject: | Re: dec*(), *dec(), base_convert() and negative numbers | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-25008@lists.php.net to get a copy of this message | ||
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