Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75568 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 38561 invoked from network); 15 Jul 2014 22:12:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Jul 2014 22:12:58 -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.174 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.217.174 mail-lb0-f174.google.com Received: from [209.85.217.174] ([209.85.217.174:43662] helo=mail-lb0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 91/6A-15121-867A5C35 for ; Tue, 15 Jul 2014 18:12:57 -0400 Received: by mail-lb0-f174.google.com with SMTP id c11so37025lbj.5 for ; Tue, 15 Jul 2014 15:12:53 -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=+DFgXjjVYUNy7WSSapovfcBZNrMOwZLs+1/n7sjYORo=; b=sI5Jbnqo96Kom/4UjKMhKHLbzkQ+/RGY2tle3FU8DGB4bSimGlL9PAqknZvlVN2Q6s VvPE+6j/A2pUIRv34r6S92V5WP49VRahhaPDegIswCUjeRCxlfWlW5DjRseosMucnw5J MBVdL3PWvJMzjDe9qYjnM9IcScCsaygTR1h0A0NFBC1Zgw2+S2zG63CJcoh83Q4H6zCx 9LKXt5EdGOsbUJZoD7EPX/2SVrXjjVEF5N0tGYYYHPnv/mlehmHWnp/Tet21KkdzzxOh z0oKSrXdJRE42zZ9DKRlR2Jsk5su2nngNIBNuCd4ipt4f0Viqu9/WDWIhbyR06HKTfgU 3p/A== X-Received: by 10.112.202.39 with SMTP id kf7mr20454265lbc.37.1405462373643; Tue, 15 Jul 2014 15:12:53 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.112.128.202 with HTTP; Tue, 15 Jul 2014 15:12:13 -0700 (PDT) In-Reply-To: References: <7646A8D1-69A2-4255-B048-D3B9F28B422F@ajf.me> Date: Wed, 16 Jul 2014 07:12:13 +0900 X-Google-Sender-Auth: 1kdb5qNZM8Yv3Ruk7ccphOr9HWo Message-ID: To: Andrea Faulds Cc: PHP internals Content-Type: multipart/alternative; boundary=001a11c3774686bdfb04fe42b535 Subject: Re: [PHP-DEV] [RFC] intdiv() From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11c3774686bdfb04fe42b535 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Andrea, On Tue, Jul 15, 2014 at 11:10 AM, Yasuo Ohgaki wrote: > 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 wro= ng >> 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 prop= er way to >> do it; it=E2=80=99s a workaround for a lack of language support for a qu= ite basic >> operation. This RFC proposes a function for integer division, intdiv(). = It >> 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 nee= d > it? > If we are going to have integer arithmetics, it may be better to have full set of operators/functions https://bugs.php.net/bug.php?id=3D30701 Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a11c3774686bdfb04fe42b535--