Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65767 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 23169 invoked from network); 11 Feb 2013 06:33:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Feb 2013 06:33:26 -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:57739] helo=smtp5-g21.free.fr) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 45/00-22812-3B098115 for ; Mon, 11 Feb 2013 01:33:26 -0500 Received: from dixsept.famillecollet.com (unknown [82.241.130.121]) by smtp5-g21.free.fr (Postfix) with ESMTP id B3B59D480BD for ; Mon, 11 Feb 2013 07:33:17 +0100 (CET) Message-ID: <511890AC.7080506@fedoraproject.org> Date: Mon, 11 Feb 2013 07:33:16 +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 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> In-Reply-To: X-Enigmail-Version: 1.5.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] double val to long val conversion issue From: remi@fedoraproject.org (Remi Collet) Le 10/02/2013 20:27, Gustavo Lopes a écrit : > This was I was afraid. That bug was just the tip of the iceberg. I > suggest we do change the the > operator to >= like you proposed, I will do it later today. > but also that we add the fmod call. The code I gave earlier had a bug btw, > as fmod can give a negative number. I changed it to this: > > long convert(double d) > { > double dmod = fmod(d, pow(2., 64.)); > if (dmod < 0) { > dmod += pow(2., 64.); > } > return (long)(unsigned long)dmod; > } > > I tested the doubles around -4e21 and it worked fine: On ppc64, $ gcc -O2 -Wall conv.c -o conv -lm $ ./conv -4000000000000001048576 2943463994971652096 -9223372036854775808 $ ./conv -4000000000000000524288 2943463994972176384 -9223372036854775808 $ ./conv -4000000000000000000000 2943463994972700672 -9223372036854775808 $ ./conv -3999999999999999475712 2943463994973224960 -9223372036854775808 $ ./conv -3999999999999998951424 2943463994973749248 -9223372036854775808 $ ./conv 9223372036854775808 -9223372036854775808 -9223372036854775808 $ ./conv 4e21 -2943463994972700672 -1 $ ./conv 4e19 3106511852580896768 -1 > > $ ./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]:= c /@ Table[-4.*^21 + i*Ulp[-4.*^21], {i, -2, 2}] > > Out[36]= {2943463994971652096, 2943463994972176384, \ > 2943463994972700672, 2943463994973224960, 2943463994973749248} > > Any reservations? For which values ? Outside LONG_MIN .. ULONG_MAX ? Remi.