Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121301 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 11712 invoked from network); 13 Oct 2023 11:44:22 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Oct 2023 11:44:22 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1E615180041 for ; Fri, 13 Oct 2023 04:44:21 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,MISSING_HEADERS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 13 Oct 2023 04:44:20 -0700 (PDT) Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-6c4b9e09528so1263026a34.3 for ; Fri, 13 Oct 2023 04:44:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697197460; x=1697802260; darn=lists.php.net; h=content-transfer-encoding:cc:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=0QrObspUa53tr0WjpL6rF/A1+lTGj04aITbQdFLM3QI=; b=f0KqxfAya+zmHsjLbCpLVkEoF5d60FPdsXlS4u6xR4OhviWmixWyICLSP3wKLjlbAx uhhN02xOq/XefNG/fGbFp9n0DD/qwL4LBOzdqyg0UBBQR8aGLP+TKmxCOf3e3k0a7zJT Alce52eez1y1zilFVKhnD8u3o2H0fzsRoZqwSgB9mV2QnpdJzfD0Lsjqi6QhBmZvUmFR 6ree3BNqxdTjFHQ7qOQkn/nffD2CLHN/OVFxLIDoVPoPccuFpl59fsSZS8cy9uBYTfO/ UW2MXjziwhm5rd1jPui8aLMPcrFjStJqB4F/OzKq6scJDRfMRndzCc57XltYnyQAW33T vbdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697197460; x=1697802260; h=content-transfer-encoding:cc:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0QrObspUa53tr0WjpL6rF/A1+lTGj04aITbQdFLM3QI=; b=KZfWgpkVguDunWAtWNz3HH7dh+7SuaG8tOmEDxc1GTz1U9pvnlfcJQsGpCRopr8WQO L2ZB0JIW8CeudMQ3Ot+Ikqhr/Sp2rzBNAYHO2vagdychrXsbfSoCdXT404EA5m+t+AV/ G9e6UFYhosJATQ7+5g2nhdY5zEqfG90rCUwAbVhzeL6llNydHexnO1F7/nxnahcA+vRU eUWDXu8PQGV6UiT7Vm0lvnEP+/oZ+1DeWrIFN75WEiwOzc5Wey2XArqjunKm6h5O2kDF YR/4atIzvjYt6RAOyRSmQhpO9k8fnZznLiZowK/CtUOibKBVBI0WB6PaKRtfXlRaag/2 IsLQ== X-Gm-Message-State: AOJu0Yzhb7IyPjBejsHaJP6qFQxkOG+bPq2QGU9yUUZT0gsNT8ly8TtR AbmC/Gm1oDNktzrVlauyMJSY5lFcxOWA4sgF8yd9x76Ox0c= X-Google-Smtp-Source: AGHT+IEKVfiSfvK3X+jbXpkGFR+oOPrCcb4prQp4EoGAAsVCISNJ+4X3VHhM1fNeJsXc02/qoERxQd9S2+o1av/Dajs= X-Received: by 2002:a9d:6b06:0:b0:6be:c1b:ded4 with SMTP id g6-20020a9d6b06000000b006be0c1bded4mr30163354otp.3.1697197459726; Fri, 13 Oct 2023 04:44:19 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 13 Oct 2023 13:44:08 +0200 Message-ID: Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] [Discussion] Rounding Integers as int From: landers.robert@gmail.com (Robert Landers) On Fri, Oct 13, 2023 at 1:26=E2=80=AFPM Jakub Zelenka wrote= : > > On Tue, Sep 26, 2023 at 11:39=E2=80=AFAM Marc Bennewitz wrote: > > > Hi internals > > > > I'd like to put a new RFC under discussion: > > https://wiki.php.net/rfc/integer-rounding > > > > > I would personally prefer a new function for rounding integers if anyone > wants to round large integers. > > The things is that the current round behaviour is consistent with a way h= ow > floats to int conversion is done for strict types. > > declare(strict_types=3D1); > > function test(float $a) { > echo $a; > } > test(987654321098765432); > > > So it won't really help that much if this function returns long for long = in > cases where the result is passed to another function expecting float. > > The main problem that I see with the current approach is that it changes > return type for an edge case that most people are not impacted with. For > example it is quite usual that people had a float value with 0 fraction > which gets json encode to int. When they decode it and use round, the > return type is suddenly int. Even though it's usually not a problem, ther= e > might be some code that expects float and maybe even assert that with > is_float. Such code will break. > > On the other hand I see use some case for rounding large integers with > negative precision. But for that to work I think it would be better to ha= ve > a special function. > > If you really want to make such change to round, then I would be prefer > targeting just 9.0 without any deprecation as I don't think the deprecati= on > should be informational only and not fixable in the code. > > Cheers > > Jakub Just to add some nuance, if you are going anywhere near the edges of ints (e.g., custom encryption prototypes from papers), you generally know that will happen -- it's math and pretty easy to verify. In those cases, you likely will be using GMP or some other extension to handle the large numbers. The point is, I highly doubt people are unknowingly using round() with exceptionally large numbers. If they are doing so, they probably know exactly what they are doing and already handle all potential edge cases or they use an extension specifically for dealing with large numbers.