Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65740 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12379 invoked from network); 9 Feb 2013 15:10:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Feb 2013 15:10:34 -0000 Authentication-Results: pb1.pair.com header.from=remi@fedoraproject.org; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=remi@fedoraproject.org; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fedoraproject.org from 212.27.42.5 cause and error) X-PHP-List-Original-Sender: remi@fedoraproject.org X-Host-Fingerprint: 212.27.42.5 smtp5-g21.free.fr Linux 2.6 Received: from [212.27.42.5] ([212.27.42.5:43405] helo=smtp5-g21.free.fr) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2E/2B-18015-6E666115 for ; Sat, 09 Feb 2013 10:10:33 -0500 Received: from dixsept.famillecollet.com (unknown [82.241.130.121]) by smtp5-g21.free.fr (Postfix) with ESMTP id B2539D4805C for ; Sat, 9 Feb 2013 16:10:23 +0100 (CET) Message-ID: <511666DE.8080809@fedoraproject.org> Date: Sat, 09 Feb 2013 16:10:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: PHP Internals X-Enigmail-Version: 1.5.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: double val to long val conversion issue From: remi@fedoraproject.org (Remi Collet) About http://git.php.net/?p=php-src.git;a=commitdiff;h=79956330fe17cfd5f60de456497541b21a89bddf (For now, I have reverted this fix) Here some explanations. LONG_MAX is 9223372036854775807 (0x7fffffffffffffff) double representation of LONG_MAX is 9223372036854775808 (d > LONG_MAX) is evaluated in double space. So is false for double which have the same value than (double)LONG_MAX. So, for (double)LONG_MAX the cast used is (long)d 9223372036854775807 on ppc64 9223372036854775808 on x86_64 (gcc without optimization) 9223372036854775807 on x86_64 (gcc -O2) PHP expected value is 9223372036854775808 (Btw, I don't understand why PHP, build on x86_64, with -O2, gives the good result, some environment mystery) Obviously, we could have different result on different platform, compiler, architecture. I will be very interested by result on other platform (mac, windows), compiler (Visual C), architecture. If we switch to the unsigned cast: (long)(unsigned long)d; The result is always 9223372036854775808 (which is expected) So my proposal, is to use the unsigned cast for (double)LONG_MAX value. - if (d > LONG_MAX) { + if (d >= LONG_MAX) { From my tests, this doesn't change anything on x86_64, and improves ppc64 (same result, so at least 9 unit tests succeed) Any comments ? If you agree, I will apply this patch again. Regards, Remi