Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123130 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 BA96F1A009C for ; Sun, 14 Apr 2024 16:42:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1713112987; bh=UpYR71PNHwq/syefg3+9zMTvk2NP06L/f0nkI5JKo/M=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=TAOYRmO7tVAc82WFeyJPOi6smBqTKox60O6/vQVlByQeBsIAqS+6ApIYVX9WRkNEn 7sjWO2S//wA4n3MGYXeRGPH3pSGYEOZoZGiijnS/LO/GYNLiThawkTRe1sKJ/+Jbg0 c/N95hKuStq6BpPC7lkbX/Wh4p1BqqjJ5UfazQys/S49fsXyjC/zbsjhBGJzbAXcND sZMxR4adhM/RLh+dHm+EKP8dmyZYKk3UM72kX72jvJa6wRDvit9mHA/DOk0C4LxDni ALGLu+g9cpTxbJ41IrT+gi4WFArVfjQlaKj8ErgT9uCUcwkTsaSQatpAAvFR64U8YK 00QNasVVrt2Xg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 434EF1804F8 for ; Sun, 14 Apr 2024 16:43:06 +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=3.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,SPF_HELO_PASS, SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from xdebug.org (xdebug.org [82.113.146.227]) by php-smtp4.php.net (Postfix) with ESMTP for ; Sun, 14 Apr 2024 16:43:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1713112949; bh=UpYR71PNHwq/syefg3+9zMTvk2NP06L/f0nkI5JKo/M=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=C2ARYWy0c6DAc2lixIcbgy2J9GKvYwXpEJOp9VEaBL4D4LgUQpXKbwp2ENrFsHx7s 9i6bC8J8RnDPaWUwh5RKyqBzL18ZF32oy8uaVK/DLjqwOKqzOszhj/SAkLZHjNgUBB sPmdSaBqwme6y2ybjfGkf1qFvqrQGH41R8WY4kbGUyUtHG7yQ0XsFz4qG+E87IxEch EneBM+fjEXGrOexyhQUX4nuwYDSkDUOehvUWP7qEF9HSGrLHTFfVv51j8vawzAwzfZ /zwzdAfLcKF1q/7e0snHUEFZKepGamXml3jJizqmwWcP5pLms1/1/D2imx+iO3L8uN xmMH9jPhrtgqw== Received: from [127.0.0.1] (unknown [185.69.145.204]) by xdebug.org (Postfix) with ESMTPSA id A6FB610C051; Sun, 14 Apr 2024 17:42:26 +0100 (BST) Date: Sun, 14 Apr 2024 17:42:26 +0100 To: internals@lists.php.net, Saki Takamachi , "Gina P. Banyard" CC: PHP internals , =?ISO-8859-1?Q?Tim_D=FCsterhus?= Subject: =?US-ASCII?Q?Re=3A_=5BPHP-DEV=5D_Incorrect_terminology?= =?US-ASCII?Q?_usage_for_rounding_modes_of_round=28=29?= User-Agent: K-9 Mail for Android In-Reply-To: <690BDBA4-4D17-4BE7-BF76-D75F85403A0E@sakiot.com> References: <690BDBA4-4D17-4BE7-BF76-D75F85403A0E@sakiot.com> Message-ID: Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: derick@php.net (Derick Rethans) On 14 April 2024 16:55:43 BST, Saki Takamachi wrote: >Hi Gina, > >> Hello internals, >>=20 >> While reviewing the PR for the "Adding bcround, bcfloor and bcceil to B= CMath" RFC [1] with the different rounding modes, >> I was made aware of the unfortunate wrong terminology usage of PHP_ROUN= D_HALF_UP and PHP_ROUND_HALF_DOWN=2E >>=20 >> Indeed, PHP_ROUND_HALF_UP is implemented as "rounding half away from ze= ro" and not "rounding half up" (which is also called rounding toward positi= ve infinity)=2E >> The behaviour for positive numbers is the same, however for negative nu= mbers the rounding *is* different=2E >> In the same vein, PHP_ROUND_HALD_DOWN is implemented as "rounding half = toward zero" and not "rounding half down" (/round half toward negative infi= nity)=2E >>=20 >> Taking -1=2E5 as our number: >> - Rounding half-up: -1 >> - Rounding half away from zero: -2 >> - Rounding half-down: -2 >> - Rounding half towards zero: -1 >>=20 >> For a detailed explanation about rounding, the Wikipedia page is of gre= at use=2E [2] >> And the following rounding calculator on Calculator Soup is useful to c= heck the differences and behaviour of different rounding modes=2E [3] >>=20 >> It should be noted that PHP is in good company about being wrong about = those two rounding modes, Java, Python, and Ruby (and probably others) are = also wrong in this regard=2E >>=20 >> Considering that PHP 8=2E4 is also adding new rounding modes via the "A= dd 4 new rounding modes to round() function" RFC [4] attempting to solve th= is issue in this next version of PHP seems like a good idea=2E >> 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 somethi= ng like this: >>=20 >> enum RoundingMode { >> case HalfAwayFromZero; >> case HalfTowardsZero; >> case HalfEven; >> case HalfOdd; >> case TowardsZero; >> case AwayFromZero; >> case NegativeInfinity; // or case Floor; >> case PositiveInfinity; // or case Ceiling; >> } >>=20 >> and change the signature of round from: >> round(int|float $num, int $precision =3D 0, int $mode =3D PHP_ROUND_HAL= F_UP): float >> to >> round(int|float $num, int $precision =3D 0, RoundingMode $mode =3D Roun= dingMode::HalfAwayFromZero): float >>=20 >> 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); >>=20 >> This should not cause any BC breaks, while allowing us to potentially i= mplement the half up/down rounding modes properly, and deprecate the existi= ng rounding constants in the future to get rid of the confusing names=2E >>=20 >> I wanted to know if anyone has any object to introducing this new enum = and signature change=2E >> The only thing I could think of is if this enum should be in a new Math= s (or Math or just Mathematics to not need to deal with regional difference= in the short spelling of "Mathematics") namespace=2E >>=20 >> Best regards, >>=20 >> Gina P=2E Banyard >>=20 >> [1] https://wiki=2Ephp=2Enet/rfc/adding_bcround_bcfloor_bcceil_to_bcmat= h >> [2] https://en=2Ewikipedia=2Eorg/wiki/Rounding >> [3] https://www=2Ecalculatorsoup=2Ecom/calculators/math/rounding-method= s-calculator=2Ephp >> [4] https://wiki=2Ephp=2Enet/rfc/new_rounding_modes_to_round_function > >In my discussions with Tim, I want to make it clear that all ideas derive= d are Tim's=2E :) > >Now, of course I agree with this, and agree with using namespaces=2E Howe= ver, if didn't use namespaces, that's fine by me=2E For reference, we found= approximately 100 pieces of code using the namespace `Math` on Github Code= Search=2E There are only a few cases for `Maths` and 0 for `Mathematics`= =2E > >Regards, > >Saki Math is American English spelling, Maths/Mathematics the British English o= ne=2E As we also have color (and not the "correct" colour), going with the Ameri= can spelling seems better=2E=20 But I would query whether we actually need it in a namespace=2E=20 cheers Derick