Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75523 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7547 invoked from network); 15 Jul 2014 02:11:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Jul 2014 02:11:08 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.172 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.217.172 mail-lb0-f172.google.com Received: from [209.85.217.172] ([209.85.217.172:57068] helo=mail-lb0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 50/64-15121-BBD84C35 for ; Mon, 14 Jul 2014 22:11:08 -0400 Received: by mail-lb0-f172.google.com with SMTP id z11so1079506lbi.3 for ; Mon, 14 Jul 2014 19:11:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=GnuXfvCkh9QIw+yquDu49JHJQOTRSlY8zyklMFeuM0M=; b=h1tJwykXmyTAd9WDp0owSB/0SlDsl36/rhaEZ49ZC4+0VkqKB74aI//XMjbN17jSZr j1JQXiVjEbEnw8YOJcl+nts1kFzD+3w5hsSut11XK/QEbSG+t3BDJnYpZRwvqjqlbnXl yvxoEmbUaB2wTHP3apx5rUbsZTA6ycUEXlJulqajvzXkhoUhc/MMGDADLIIiJJ7sqnWp S4EzcIFpWlN7kj5Tifl7yyQc6NwYUhMcORVzLiuIb+xjxoBrsoytfDaaiqeSJ7f8mBvk /iH4onURacQHpBeDWcDf9IOG7ncwuhJn00gorV8NH1fHY/BjmB2pznlNnmjHLun8X2/L sW/g== X-Received: by 10.152.183.162 with SMTP id en2mr16663507lac.23.1405390264929; Mon, 14 Jul 2014 19:11:04 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.112.128.202 with HTTP; Mon, 14 Jul 2014 19:10:24 -0700 (PDT) In-Reply-To: <7646A8D1-69A2-4255-B048-D3B9F28B422F@ajf.me> References: <7646A8D1-69A2-4255-B048-D3B9F28B422F@ajf.me> Date: Tue, 15 Jul 2014 11:10:24 +0900 X-Google-Sender-Auth: kotBVHEHMTzTrAfAudmw9DHEmqw Message-ID: To: Andrea Faulds Cc: PHP internals Content-Type: multipart/alternative; boundary=001a11345d5283142004fe31ebc7 Subject: Re: [PHP-DEV] [RFC] intdiv() From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11345d5283142004fe31ebc7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Andrea, On Tue, Jul 15, 2014 at 9:14 AM, Andrea Faulds wrote: > PHP currently lacks a way to do integer division. You can floor or int > cast a floating-point division, but beyond 53-bits that produces the wron= g > result: > > $ sapi/cli/php -r 'var_dump((int)(PHP_INT_MAX / 3));' > int(3074457345618258432) > > Furthermore, using a floating-point division isn=E2=80=99t really a prope= r way to > do it; it=E2=80=99s a workaround for a lack of language support for a qui= te basic > operation. This RFC proposes a function for integer division, intdiv(). I= t > would work properly with 64-bit values: > > $ sapi/cli/php -r 'var_dump(intdiv(PHP_INT_MAX, 3));' > int(3074457345618258602) > We have GMP object from 5.6 and we can do [yohgaki@dev php-5.6]$ ./php-bin -r '$i =3D gmp_init('21342'); $a =3D $i / = 3; var_dump($a);' object(GMP)#2 (1) { ["num"]=3D> string(4) "7114" } [yohgaki@dev php-5.6]$ ./php-bin -r '$i =3D gmp_init('21342'); $a =3D $i * 99999999; var_dump($a);' object(GMP)#2 (1) { ["num"]=3D> string(13) "2134199978658" } IMHO, GMP is the choice when precise computation is needed as it could be any number. Native integer type is much faster for sure. Question is do we really need it? Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a11345d5283142004fe31ebc7--