Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:43639 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42325 invoked from network); 6 Apr 2009 18:00:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Apr 2009 18:00:54 -0000 Authentication-Results: pb1.pair.com header.from=php_lists@realplain.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=php_lists@realplain.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain realplain.com from 209.151.69.1 cause and error) X-PHP-List-Original-Sender: php_lists@realplain.com X-Host-Fingerprint: 209.151.69.1 liberty.vosn.net Linux 2.4/2.6 Received: from [209.151.69.1] ([209.151.69.1:35100] helo=liberty.vosn.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3D/9E-02528-5534AD94 for ; Mon, 06 Apr 2009 14:00:53 -0400 Received: from 75-120-53-110.dyn.centurytel.net ([75.120.53.110]:56617 helo=pc1) by liberty.vosn.net with smtp (Exim 4.69) (envelope-from ) id 1Lqt7p-0001bM-FC; Mon, 06 Apr 2009 12:00:49 -0600 Message-ID: To: "PHP Internals List" , "Daniel Convissor" References: <20090402163317.GA25864@panix.com> Date: Mon, 6 Apr 2009 13:00:47 -0500 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5512 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - liberty.vosn.net X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - realplain.com Subject: Re: [PHP-DEV] [PATCH] double to long conversion change From: php_lists@realplain.com ("Matt Wilmas") Hi Dan, ----- Original Message ----- From: "Daniel Convissor" Sent: Thursday, April 02, 2009 > Hi Matt: > > On Sat, Mar 14, 2009 at 09:30:42AM -0500, Matt Wilmas wrote: >> >> But of course with >> doubles, precision has been lost long before 2^63 anyway, as far as >> increments of 1 (it's 1024 at 2^63). > > I just ran into these issues in PHP 5.2.8 on 64 bit Linux while running > examples I'm using to improve our documentation surrounding bitwise > operators, bindec() and decbin(). > > The integer float conversions start failing above 2^53, meaning > 9007199254740993 is the first integer that doesn't work. As you noted, > ints divisible by 1024 are fine. I can provide the test script to anyone > who needs it. Sorry I didn't get back to you sooner, but unless I'm missing something, you're talking about converting long/int to double/float. That's the opposite of this thread subject, which is how to convert a double to a long when it's out of the range of a long. :-) But, for what you're testing, that's the behavior I'd expect -- once you've reached the precision of a double, you'll only get the closest representation possible (and of course a 64-bit long is more precise than a double since there's no floating point to represent). Also, I assume what can be represented by a double is the same across platforms, if it's IEEE 754. Just curious though, you're saying that all whole numbers (from long) below 2^53 are representable? (Powers of 2 should always be OK.) When writing a big literal number on a 32-bit system, I'm seeing much lower than that (around 2^40), but in that case conversion is happening from a string, digit-by-digit, instead of directly from a 64-bit integer type, so maybe that's why... > A bash script I put together makes it look like things work correctly in > the shell. So it seems this is a PHP thing, not a Linux thing. That's interesting, though I don't know much about shell script stuff (or other *nix details ;-)). Like I said, I figure a double type should behave the same everywhere. Unless the shell/bash uses a *long* double type (twice as big as a regular double)? *shrug* > Am I correct in believing your changes will take care of these issues? > It seems you're looking to patch 5.3 and HEAD. Are there thoughts of > applying this to 5.2? > > Thanks, > > --Dan > > Note: The guy who put the box together says everything on it is built > against 64 bit libraries. - Matt