Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120373 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 69529 invoked from network); 21 May 2023 05:16:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 May 2023 05:16:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8C0C1180083 for ; Sat, 20 May 2023 22:16:38 -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.2 required=5.0 tests=BAYES_05,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS34011 80.237.132.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wp160.webpack.hosteurope.de (wp160.webpack.hosteurope.de [80.237.132.167]) (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 ; Sat, 20 May 2023 22:16:37 -0700 (PDT) Received: from [2a02:8109:9d40:1d44:40b6:f5d3:c567:d46c]; authenticated by wp160.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) id 1q0bQq-0000Rg-7E; Sun, 21 May 2023 07:16:36 +0200 Content-Type: multipart/alternative; boundary="------------0ghBSXU4pofltGRPi3lCBzI0" Message-ID: <05b7e019-27d4-e6a9-2088-f712c22317a9@mabe.berlin> Date: Sun, 21 May 2023 07:16:35 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 To: PHP internals Content-Language: en-US X-bounce-key: webpack.hosteurope.de;marc@mabe.berlin;1684646198;98d19b2e; X-HE-SMSGID: 1q0bQq-0000Rg-7E Subject: rounding integers From: marc@mabe.berlin (Marc) --------------0ghBSXU4pofltGRPi3lCBzI0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi all, The "round" function supports rounding to significant digits before the decimal point which can be very helpful but unfortunately it's handling everything as floating point numbers which in the end can lead to inaccurate results.     printf("%d\n", round(987654321098765432, -1) // 987654321098765440 instead of 987654321098765430 To be fair it's also documented as such: > round — Rounds a float round(int|float $num, int $precision = 0, int $mode = PHP_ROUND_HALF_UP): float I would like to propose to change this function to keep the given type and proper handle integers as well: > round — Rounds a number /** @template T of int|float */ round(T $num, int $precision = 0, int $mode = PHP_ROUND_HALF_UP): T Do you think this could be an acceptable BC-break or should this be a different function? Thanks, Marc --------------0ghBSXU4pofltGRPi3lCBzI0--