Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:25006 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90963 invoked by uid 1010); 27 Jul 2006 13:32:04 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 90945 invoked from network); 27 Jul 2006 13:32:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jul 2006 13:32:04 -0000 X-PHP-List-Original-Sender: php_lists@realplain.com X-Host-Fingerprint: 69.179.208.43 msa3-mx.centurytel.net Linux 2.4/2.6 Received: from ([69.179.208.43:49595] helo=msa3-mx.centurytel.net) by pb1.pair.com (ecelerity 2.1.1.3 r(11751M)) with ESMTP id B6/9F-23194-D3BB8C44 for ; Thu, 27 Jul 2006 09:10:22 -0400 Received: from pc1 (69-29-174-70.dyn.centurytel.net [69.29.174.70]) by msa3-mx.centurytel.net (8.13.6/8.13.6) with SMTP id k6RDAHbh003638; Thu, 27 Jul 2006 08:10:18 -0500 Message-ID: <016401c6b17e$027908c0$0201a8c0@pc1> To: , "Michael Wallner" References: <00c601c6b095$a1a2e220$0201a8c0@pc1> <010601c6b169$225b9eb0$0201a8c0@pc1> <6E.DD.23194.071B8C44@pb1.pair.com> Date: Thu, 27 Jul 2006 08:10:18 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1807 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 Subject: Re: [PHP-DEV] dec*(), *dec(), base_convert() and negative numbers From: php_lists@realplain.com ("Matt W") Hi Michael, ----- Original Message ----- From: "Michael Wallner" > Matt W wrote: > > Hi again, > > > [...] > > I don't see what you're trying to fix. > > $ cli -r 'var_dump((int)hexdec(dechex(-123)), (int)(float)sprintf("%u",-123), (int)0xffffff85);' > int(-123) > int(-123) > int(-123) The main "fix" (upgrade) is to let the dec*() functions convert numbers >= 2^32. But I'm *wondering* whether *this* should be changed: C:\math-old>php -r "var_dump(hexdec(dechex(-123)));" float(4294967173) Your (int) typecast changed that of course. If the dec*() functions handle numbers whose absolute value is >= 2^32, how is a negative double supposed to be handled? Absolute value, I assume. But that's different than negative int handling now (internal long converted to unsigned long). If double's were to be the same way, and there was an unsigned double type, passing -5000000000 would result in an insanely huge number after being made "unsigned" internally like now. 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. :-)) 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. > Regards, > -- > Michael Matt