Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123131 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id BB4571A009C for ; Sun, 14 Apr 2024 16:49:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1713113421; bh=wgwN2hrZR/RJ8XOKvTqxbIZhxlSaFZ8BkK4HlZeS1kw=; h=Date:Subject:To:References:From:In-Reply-To:From; b=dW/Pvzw9kwMZa1fnhiE2cdqN7FL2SPRnNWlkvowXkkeU0ciXhqw2FtbojNIaXJuK5 1FSJnprS3+U2bOT5LoX8vR20oEmPWLfK1jM8K58/I+jQ212REcauUZhC5DFE0JVXb9 O2cj1/wOWAS3vhlCSh78YLGCMYqZakmJXVpeJPyTrqR8hYikSlsS3yp4MGRcPXmCW5 ftwnGJMFzHQeZi9hY2rTXtKvfBzNwVrbBB7OC2C2/EZeC8V20xzu3JMGdYKjKFAnqr sTVa+xcGm0BBc1jz/2asC8SaR4Ba3jRchX8Tu+kUnlzwqRKCaJAtzI2lOOfxgi1JvH hW5IzMND7Peiw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A70BA180047 for ; Sun, 14 Apr 2024 16:50:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 14 Apr 2024 16:50:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1713113383; bh=VwoHim2w4EWyKF5fa7T8hFVSHTYnFB4PB0RL8xY7zRo=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=eExbwWiMWOHuNf1GO3xtydsS6NTgZJcH6+GbYz6uYGp38lPYzpTSrfocUKv+5JV7/ ra3uimsdoLd1j/nr4RKY7TjgSLvRDOn1L15jIKyEqbAbDjK7XTwDt7OQd3n4LqnSrq rnWM+WRoreXf+eSUKKlMrI58IZkCgZgRmom3xJzQlDsw+PJNH+ZE2DAE4vhX4WCfYH Vi/xrqZNwVHlfraSAFSuoaertDhZ2X8TdE0Y2FLxWcREfP9qtiUQFxLnpreCCvGpbL 8daiq0iLTaN+56xojH3DKrDK5TRZB15SHSci7svKopwxGdy8zGrn7LiIzGT8/hQW9n zkijFiTrbb+qA== Message-ID: Date: Sun, 14 Apr 2024 18:49:42 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Subject: Re: [PHP-DEV] Incorrect terminology usage for rounding modes of round() To: "Gina P. Banyard" , PHP internals References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi On 4/14/24 16:33, Gina P. Banyard wrote: > Considering that PHP 8.4 is also adding new rounding modes via the "Add 4 new rounding modes to round() function" RFC [4] attempting to solve this issue in this next version of PHP seems like a good idea. > In my discussions with Saki about this issue, it seems that her and Tim have thought about creating a new enum for rounding modes, looking something like this: > > enum RoundingMode { > case HalfAwayFromZero; > case HalfTowardsZero; > case HalfEven; > case HalfOdd; > case TowardsZero; > case AwayFromZero; > case NegativeInfinity; // or case Floor; > case PositiveInfinity; // or case Ceiling; > } Indeed. > and change the signature of round from: > round(int|float $num, int $precision = 0, int $mode = PHP_ROUND_HALF_UP): float > to > round(int|float $num, int $precision = 0, RoundingMode $mode = RoundingMode::HalfAwayFromZero): float > > and changing the definition of the existing constants to effectively be: > define('PHP_ROUND_HALF_UP', RoundingMode::HalfAwayFromZero); > define('PHP_ROUND_HALF_DOWN', RoundingMode::HalfTowardsZero); > define('PHP_ROUND_HALF_EVEN', RoundingMode::HalfEven); > define('PHP_ROUND_HALF_ODD', RoundingMode::HalfOdd); > > This should not cause any BC breaks, while allowing us to potentially implement the half up/down rounding modes properly, and deprecate the existing rounding constants in the future to get rid of the confusing names. For PHP 8.4, I'd first make it `int|RoundingMode` to keep the constant values the same (in case the constants are re-used by a userland library). Narrowing it down to just RoundingMode and updating the constants can happen in a later version. > I wanted to know if anyone has any object to introducing this new enum and signature change. > The only thing I could think of is if this enum should be in a new Maths (or Math or just Mathematics to not need to deal with regional difference in the short spelling of "Mathematics") namespace. I don't think it should be in a namespace. The name is sufficiently unique and clear. Without a broader concept for the namespace, we probably should not introduce one. Best regards Tim Düsterhus