Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75532 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50674 invoked from network); 15 Jul 2014 12:11:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Jul 2014 12:11:44 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.200 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.200 imap1-2.ox.privateemail.com Received: from [192.64.116.200] ([192.64.116.200:49738] helo=imap1-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 27/2A-15121-D7A15C35 for ; Tue, 15 Jul 2014 08:11:42 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 575E0B0008B; Tue, 15 Jul 2014 08:11:39 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at imap1.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap1.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id LmWFTnmA8x8e; Tue, 15 Jul 2014 08:11:39 -0400 (EDT) Received: from [192.168.0.15] (unknown [90.210.122.167]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id DA330B00085; Tue, 15 Jul 2014 08:11:37 -0400 (EDT) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) In-Reply-To: Date: Tue, 15 Jul 2014 13:11:34 +0100 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <7646A8D1-69A2-4255-B048-D3B9F28B422F@ajf.me> To: bishop@php.net X-Mailer: Apple Mail (2.1878.6) Subject: Re: [PHP-DEV] [RFC] intdiv() From: ajf@ajf.me (Andrea Faulds) On 15 Jul 2014, at 03:31, Bishop Bettini wrote: > I need some education. Can you elaborate on the specific situations = where integer division would be used without other functions from bcmath = or gmp? >=20 > 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? Sure. Say I have a number of seconds which I wish to split into years, = days, hours, minutes and seconds, for example: $s =3D 1000000; $seconds =3D $s % 60; $minutes =3D intdiv($s, 60) % 60; $hours =3D intdiv($s, 3600) % 24; $days =3D intdiv($s, 3600 * 24) % 365; $years =3D intdiv($s, 3600 * 24 * 365); Currently, you=92d have to cheat and use floating-point division: $x =3D 1000000; $seconds =3D $s % 60; $minutes =3D (int)($s / 60) % 60; $hours =3D (int)($s / 3600) % 24; $days =3D (int)($s / (3600 * 24)) % 365; $years =3D (int)($s / (3600 * 24 * 365)); The second one is a bit of a hack, really, but it would probably work = most of the time since realistically nobody is using >53-bit time values = at the moment (though people are using >32-bit values, so that 64-bit = RFC can=92t come soon enough given Y2K38). However, intdiv() is perhaps not the best way to implement it or the = best syntax. -- Andrea Faulds http://ajf.me/