Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65744 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87771 invoked from network); 9 Feb 2013 23:02:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Feb 2013 23:02:39 -0000 Authentication-Results: pb1.pair.com smtp.mail=Terry@ellisons.org.uk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=Terry@ellisons.org.uk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain ellisons.org.uk from 79.170.44.47 cause and error) X-PHP-List-Original-Sender: Terry@ellisons.org.uk X-Host-Fingerprint: 79.170.44.47 mail47.extendcp.co.uk Received: from [79.170.44.47] ([79.170.44.47:34847] helo=mail47.extendcp.co.uk) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 03/27-53163-C85D6115 for ; Sat, 09 Feb 2013 18:02:37 -0500 Received: from host86-184-170-184.range86-184.btcentralplus.com ([86.184.170.184] helo=[192.168.1.91]) by mail47.extendcp.com with esmtpa (Exim 4.80.1) id 1U4JRA-0001nG-Jt; Sat, 09 Feb 2013 23:02:24 +0000 Message-ID: <5116D57F.6030802@ellisons.org.uk> Date: Sat, 09 Feb 2013 23:02:23 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: Pierre Joye CC: Remi Collet , PHP Internals References: <511666DE.8080809@fedoraproject.org> In-Reply-To: Content-Type: multipart/alternative; boundary="------------000805020403010204050705" X-Authenticated-As: Terry@ellisons.org.uk Subject: Re: [PHP-DEV] double val to long val conversion issue From: Terry@ellisons.org.uk (Terry Ellison) --------------000805020403010204050705 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 09/02/13 15:47, Pierre Joye wrote: > hi Remi > > On Sat, Feb 9, 2013 at 4:10 PM, Remi Collet wrote: >> 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; >> Any comments ? > IIRC, on windows/visualC, no matter if it is x86 or x64, long is > always 32bits, so it won't change the size of long. See http://en.wikipedia.org/wiki/LLP64#64-bit_data_models for a good description of this mess. AFAIK many packages that target both 32 and 64 bit environments MS and *nix, define explicitly adopt XXX_int32, XXX_uint32, XXX_int64, XXX_uint64, ... datatypes and use wrappers to map these onto the appropriate visualC / gcc types. As far as I can see, PHP doesn't and seems to use long and int almost interchangeably which causes problems as LP64/I32LP64 and LLP64/IL32P64 are very different. This is one reason for 64-bit support on Windows being problematic. It would be good for PHP to have a road map to removed data model-specific potholes, say by 5.6 or 5.7. //Terry --------------000805020403010204050705--