Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65762 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81027 invoked from network); 10 Feb 2013 19:28:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Feb 2013 19:28:00 -0000 Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.21 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.21 smtp1.ist.utl.pt Linux 2.6 Received: from [193.136.128.21] ([193.136.128.21:44662] helo=smtp1.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 40/CA-20900-FB4F7115 for ; Sun, 10 Feb 2013 14:28:00 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp1.ist.utl.pt (Postfix) with ESMTP id 62EF2700044A; Sun, 10 Feb 2013 19:27:56 +0000 (WET) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp1.ist.utl.pt ([127.0.0.1]) by localhost (smtp1.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id Zv0aYqMRMGpO; Sun, 10 Feb 2013 19:27:56 +0000 (WET) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp1.ist.utl.pt (Postfix) with ESMTP id 103C37000430; Sun, 10 Feb 2013 19:27:55 +0000 (WET) Received: from damnation.nl.lo.geleia.net (unknown [IPv6:2001:470:94a2:4:21d:baff:feee:cc0b]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id B89CC2006C3E; Sun, 10 Feb 2013 19:27:54 +0000 (WET) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "PHP Internals" , "Remi Collet" References: <511666DE.8080809@fedoraproject.org> <51172819.4000806@sugarcrm.com> <51174790.8040805@fedoraproject.org> <511751C5.1020906@fedoraproject.org> <51175BDD.9040705@sugarcrm.com> <5117BA92.8080307@fedoraproject.org> Date: Sun, 10 Feb 2013 20:27:48 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: Quoted-Printable Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_I=2ES=2ET=2E?= Message-ID: In-Reply-To: <5117BA92.8080307@fedoraproject.org> User-Agent: Opera Mail/12.12 (Linux) Subject: Re: [PHP-DEV] double val to long val conversion issue From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") On Sun, 10 Feb 2013 16:19:46 +0100, Remi Collet = = wrote: > Le 10/02/2013 15:58, Gustavo Lopes a =C3=A9crit : > >> Can you test this program on ppc64: > > $ gcc -O3 -lm conv.c && ./a.out 9223372036854775808 > -9223372036854775808 -9223372036854775808 > > $ gcc -O3 -lm conv.c && ./a.out 4e21 > -2943463994972700672 -1 > > $ gcc -O3 -lm conv.c && ./a.out 4e19 > 3106511852580896768 -1 > > >> I get this: >> $ gcc -O3 -lm conv.c && ./a.out 9223372036854775808 >> -9223372036854775808 -9223372036854775808 >> $ gcc -O3 -lm conv.c && ./a.out 4e21 >> -2943463994972700672 0 >> $ gcc -O3 -lm conv.c && ./a.out 4e19 >> 3106511852580896768 0 This was I was afraid. That bug was just the tip of the iceberg. I sugge= st = we do change the the > operator to >=3D like you proposed, but also that= we = add the fmod call. The code I gave earlier had a bug btw, as fmod can gi= ve = a negative number. I changed it to this: long convert(double d) { double dmod =3D fmod(d, pow(2., 64.)); if (dmod < 0) { dmod +=3D pow(2., 64.); } return (long)(unsigned long)dmod; } I tested the doubles around -4e21 and it worked fine: $ ./a.out -4000000000000001048576 2943463994971652096 -9223372036854775808 $ ./a.out -4000000000000000524288 2943463994972176384 -9223372036854775808 $ ./a.out -4000000000000000000000 2943463994972700672 -9223372036854775808 $ ./a.out -3999999999999999475712 2943463994973224960 -9223372036854775808 $ ./a.out -3999999999999998951424 2943463994973749248 -9223372036854775808 In[36]:=3D c /@ Table[-4.*^21 + i*Ulp[-4.*^21], {i, -2, 2}] Out[36]=3D {2943463994971652096, 2943463994972176384, \ 2943463994972700672, 2943463994973224960, 2943463994973749248} Any reservations? -- = Gustavo Lopes