Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75621 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74365 invoked from network); 17 Jul 2014 00:25:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jul 2014 00:25:41 -0000 Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.192.175 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.192.175 mail-pd0-f175.google.com Received: from [209.85.192.175] ([209.85.192.175:40168] helo=mail-pd0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 07/07-37298-40817C35 for ; Wed, 16 Jul 2014 20:25:41 -0400 Received: by mail-pd0-f175.google.com with SMTP id r10so624240pdi.34 for ; Wed, 16 Jul 2014 17:25:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=2zznHsmsvNgdcZs3zPE2J0eAXRb0TnMewPZL1OTDP24=; b=ivWdjvQN+ri+zFBpnaFGdwdCE3h0VlTUtwRaQbuGtNPCqf5hrJGNi3etztmMVZf3rD 4jj+C54nJ3Di+GDA9OYVK3gHs73fnsdzYTrPMKxOm+opS4rd2M5GVE8RLXbtxB9b7c52 gDBNWBN8TI3uxO0s0BdeMdIKrhhBL8TtCY9a/1GpTcq7Pwft0Z7+nslEsAAkYTLYxRnh YVWKeqX4a/UqXT1F9pAoyS557BhYDdXykOuQgSXe5uKgfPLhiYEOEGto70xorFfwqMdU oJClsXRTHoXRCSDGIsB8KopY1dbO7mr1cAx/v9thI6vLd6o50Y7EwwR9G0jj2pg3ilfs ncsA== X-Gm-Message-State: ALoCoQnHY/yDrTrnPi8AMY838UOyIYdiFc9CN6vn43Fku5tK4oQOLtg7qzUKapNy9FkJSnHxPse+ MIME-Version: 1.0 X-Received: by 10.70.54.162 with SMTP id k2mr14019789pdp.138.1405556738201; Wed, 16 Jul 2014 17:25:38 -0700 (PDT) Sender: php@golemon.com Received: by 10.70.21.35 with HTTP; Wed, 16 Jul 2014 17:25:38 -0700 (PDT) X-Originating-IP: [184.250.48.41] In-Reply-To: <37F89E54-C5B9-4E81-9D1B-660190BDB1FF@ajf.me> References: <7646A8D1-69A2-4255-B048-D3B9F28B422F@ajf.me> <37F89E54-C5B9-4E81-9D1B-660190BDB1FF@ajf.me> Date: Wed, 16 Jul 2014 17:25:38 -0700 X-Google-Sender-Auth: CFfc6sGqKmWWH7ttzUE2dgipuMM Message-ID: To: Andrea Faulds Cc: bishop@php.net, PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] intdiv() From: pollita@php.net (Sara Golemon) On Wed, Jul 16, 2014 at 8:15 AM, Andrea Faulds wrote: > Nikita Popov doesn=E2=80=99t seem to be a fan of the %% syntax, so it may= be subject to change, though I think it=E2=80=99s the best I=E2=80=99ve he= ard so far. ;) > Nor am I. Here's a thought though: How about just making / return int when there's no remainder. Looking at this code, you might think it's inefficent: double dres =3D a / b; long lres =3D a / b; if (a % b) { return dres; } else { return lres; } But in fact at -O1, gcc will optimize this (probably clang and others as well) to a single idivq instruction and only do the cvtsi2sdq in the dres case. My point being, we can just make division with an integral result return a result of integer division without altering the syntax or adding a perf hit. -Sara