Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75524 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9867 invoked from network); 15 Jul 2014 02:31:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Jul 2014 02:31:09 -0000 Authentication-Results: pb1.pair.com smtp.mail=bishop.bettini@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=bishop.bettini@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.42 as permitted sender) X-PHP-List-Original-Sender: bishop.bettini@gmail.com X-Host-Fingerprint: 209.85.215.42 mail-la0-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:57699] helo=mail-la0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0C/B4-15121-A6294C35 for ; Mon, 14 Jul 2014 22:31:08 -0400 Received: by mail-la0-f42.google.com with SMTP id pn19so3501268lab.15 for ; Mon, 14 Jul 2014 19:31:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:sender:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=xUID3TZEOO2BP3lHd39LtEvWKbfSQcPpyzyfZR1zMOM=; b=X5DVCwVF8HIku7UULh7kvZtBhQy8K08mRgTIisLboS2x+eDl0xvTzzkzDoyvmKz+cz WSjYqdCaKWxRTYH4BC8MMht6KgWTq3hLZKNrD/ftg78g0cxF9dCiY+9aBrezX63IbtaZ wEMTK5NB2gYwofkfB54a99qlBLWcDte2MZWZ3biRDXVN8+Ch5xoEX4cBID5GyUbWX7xp BlSFxoqRDLQj+n8kUUQ6IvqCVGU2l0eOc3t6NVM/mHZ56Pg2XBiyxtMReyXG2N9GWaBs hJNBOJ8NLyUiT+M7gaVFCDDUPfJhe1nmtz7fmhk+7SJOYUDoN4jn7GC+wV6Wl1uPGVcw cU9A== MIME-Version: 1.0 X-Received: by 10.152.206.105 with SMTP id ln9mr16930532lac.45.1405391463605; Mon, 14 Jul 2014 19:31:03 -0700 (PDT) Reply-To: bishop@php.net Sender: bishop.bettini@gmail.com Received: by 10.152.242.34 with HTTP; Mon, 14 Jul 2014 19:31:03 -0700 (PDT) Received: by 10.152.242.34 with HTTP; Mon, 14 Jul 2014 19:31:03 -0700 (PDT) In-Reply-To: <7646A8D1-69A2-4255-B048-D3B9F28B422F@ajf.me> References: <7646A8D1-69A2-4255-B048-D3B9F28B422F@ajf.me> Date: Mon, 14 Jul 2014 22:31:03 -0400 X-Google-Sender-Auth: SMCNRH7RO_TZupJE0Nm0K9lp5SE Message-ID: To: Andrea Faulds Cc: PHP internals Content-Type: multipart/alternative; boundary=001a11349758f56b0704fe3232ff Subject: Re: [PHP-DEV] [RFC] intdiv() From: bishop@php.net (Bishop Bettini) --001a11349758f56b0704fe3232ff Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Andrea, I need some education. Can you elaborate on the specific situations where integer division would be used without other functions from bcmath or gmp? I see in the RFC you mention seconds to hh:mm and index to rows/cols, but can you give some actual "before" and "after" samples? Like this is how it would be done today without intdiv, and here's how it would be done after? Regards, bishop On Jul 14, 2014 8:15 PM, "Andrea Faulds" wrote: > Good evening again, > > 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) > > It works exactly as you=E2=80=99d expect it to. If you divide by zero, it= does > exactly the same thing the division operator does (E_WARNING and returns > FALSE). > > While this is simple enough, I=E2=80=99m also considering possibly shorte= ning it > to div() (more likely to cause conflicts, but easier to type), implementi= ng > it as an internal function (=C3=A0 la pow()), and perhaps implementing it= as an > infix operator (3 div 2 =3D=3D=3D 1). > > The RFC is here: https://wiki.php.net/rfc/intdiv > > It elaborates a little more, so I=E2=80=99d suggest reading it first. Wha= t are > your thoughts? I think this is a simple and obvious addition. > > Thanks! > -- > Andrea Faulds > http://ajf.me/ > > > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --001a11349758f56b0704fe3232ff--