Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:24997 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50203 invoked by uid 1010); 27 Jul 2006 11:20:56 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 50188 invoked from network); 27 Jul 2006 11:20:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jul 2006 11:20:56 -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:36621] helo=msa3-mx.centurytel.net) by pb1.pair.com (ecelerity 2.1.1.3 r(11751M)) with ESMTP id E5/2A-23194-73898C44 for ; Thu, 27 Jul 2006 06:40:56 -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 k6RAeqpP025926 for ; Thu, 27 Jul 2006 05:40:52 -0500 Message-ID: <010601c6b169$225b9eb0$0201a8c0@pc1> To: References: <00c601c6b095$a1a2e220$0201a8c0@pc1> Date: Thu, 27 Jul 2006 05:40:52 -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 again, I realize I might not get any answer about updating these little ol' functions :-/, but it'd be nice to hear something one way or the other so I can submit an acceptable patch with correct behavior. After thinking about it more, are negative numbers even "officially supported" with the dec[bin|hex|oct] functions? You won't get anything close to the original back with *dec(dec*(-123)). Since base_convert() uses the number's absolute value, I'm thinking the only reason for using "unsigned long" for the dec*() functions is to handle cases where a PHP double is between LONG_MAX and ULONG_MAX. If so, I think absolute value can be used everywhere. Or again, should I update the functions to correctly accept and return negative values? But I'm not sure if negative bin/hex/oct strings are desired (semantically). Thanks for any simple guidance! Matt ----- Original Message ----- From: "Matt W" Sent: Wednesday, July 26, 2006 > Hi all, > > I was just updating the dec[bin|hex|oct] functions to convert numbers >= > 2^32 since the [bin|hex|oct]dec counterparts were updated way back in PHP > 4.1. > > My question is if negative numbers should be handled any differently. Now > negative longs are converted to unsigned which gives a weird result for > regular users IMO. The *dec() functions ignore negative strings. Because > of the way base_convert() works, if you pass a negative number (gets > converted to string), the result will be from the absolute value instead of > what you get with dec*(). > > *) Should the dec*() functions continue to convert negative longs to > unsigned and use absolute value for doubles? > > *) Should absolute value always be used, like with base_convert()? > > *) Should everything be changed to support negative numbers going both > directions (to or from base)? > > > Thanks, > Matt