Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123067 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 8EF3D1A009C for ; Tue, 9 Apr 2024 19:21:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712690523; bh=TIC/9Yl9lsgcqHrXQqYLYN7sAxXbmeI1VJmAtsv+Vrg=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=lC1m9eH/UI+aWHuEnoBXqTo4WYd6RDIZfgyBJi6orMS/nm4wP+386hsCawgxDMXmS xcJQbWSe4BuuDAWXcpCPKgxc/BxND9eK/e1YQNfJB0n0EeVFrgYdog2+HBS2tThtsb qb/vGeulukutiOkIbqtYKCkmrfkDEsv4IxhqYqG4A03GGvcYrmCurcgnJYohxyI7CH V9v7DY55LsksUxdGykMVYg9p5+ZNzf8xaBPoA7KqiomSqDix0wrwAIN2srd5Jnusdy BoBZnosawFyR0bdyPQb37sfZjDbZ+0Sa4bpbICuqdH6BfKyxOKElzzcGMcxuyNfWy+ bOsuikA1ugzVw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D66931806DA for ; Tue, 9 Apr 2024 19:22:02 +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=2.4 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLACK,URIBL_SBL_A 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 ; Tue, 9 Apr 2024 19:22:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1712690488; bh=e/YF/5a+FbeMlarwNgIdc2HRLz6Ay6SCgNWlnXi4IJI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=g5xU2umFvy+HRIjjV9Hzo3g4uKiSz1KNrGyOkkh6N3ajZfqFi/PEnXNkn9I6/RiFu Oxk1EhJ43cGvlOaTt51aTCPrQMbb7DkET5A1NBH+MkI6j0IGpdou76W8haEn+Mn4wW PU79jyjAxjO6SXItVw0yNu1IUdiEae1BN1Am/5XXW1KNtLjagIyO11CEjiB4+3OxuR YVYPjrD6gPCFyh7iPg/oS8AYY0b2worzI5It8L2+NNSPdMkFNM4wf5f9U++Kw8CRTM DUFklqonwTeIneFFcsX2PNKAMSrX4CxcTDS8NGbISliMZr8jCIpxZ1+8PiSx5rEtqC 77QX8SHTQLPIw== Message-ID: Date: Tue, 9 Apr 2024 21:21:27 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Subject: Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath To: Saki Takamachi Cc: internals@lists.php.net References: <959ccc6e-1d5c-48c0-9357-80e38becd1c5@bastelstu.be> 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/8/24 02:08, Saki Takamachi wrote: >> - The full “stub” should probably include an explicit "implements Stringable" for clarity. > > Agree. I describe it explicitly during implementation. > I don't see a change made, so perhaps I was unclear in what I said. What I meant was: Please add a full stub example including all the interfaces, properties, and methods. It's currently split across multiple code blocks and the interfaces are missing entirely. Example: final readonly class Number implements \Stringable { public string $value; // Further properties omitted for brevity. public function add(Number|string|int $num): Number {} // Further methods omitted for brevity. } >> - I don't want to expand the scope of your RFC further than necessary, but for the rounding mode, I wonder if we should first add the RoundingMode enum that has been suggested during the discussion of the "Add 4 new rounding modes to round() function" RFC. It would make the type for the `Number::$roundMode` property much clearer than the current `int`. I expect the addition of such an enum to be a pretty simple RFC that would not need much discussion. I'd be happy to co-author it. > > Oh, that's a good idea. Makes sense. I think it would be simpler to prepare an RFC separate from this RFC, so I'm going to create one right away. Once you have a certain amount of content, I would be happy if you could check it out and make corrections if necessary. > Sure, just send me an email and I'm happy to look over it before you put it up for discussion. >> - For `format()`, I'm not sure whether we should actually add the function. While we have number_format() for regular numbers with the same signature, it fails to account for the different language and cultures in the world. Specifically `number_format()` cannot correctly format numbers for en_IN (i.e. English in India). In India numbers are not separated every three digits, but rather the three right-most digits and then every two digits. Here's in example: 1,23,45,67,890. I believe formatting should be best left for ext/intl. > > I'm not very familiar with ext/intl, but is there a way to format a string type number without converting it to a float? It appears the underlying icu4c library supports formatting numeric strings, yes: https://unicode-org.github.io/icu-docs/apidoc/dev/icu4c/classicu_1_1NumberFormat.html#a8ed2ca7b9a65bf08c4ef81bbf9680f0d >> - I'm not sure if the priority for the rounding modes is sound. My gut feeling is that operations on numbers with different rounding modes should be disallowed or made explicit during the operation (much like the scale for a division), but I'm not an expert in designing numeric APIs, so I might be wrong here. > > As mentioned in the RFC, the problem here is commutative calculations (add, sub, mul). This means that even if specify `$roundingMode` during these calculations, `$roundingMode` will not be used in these calculations. Calculations that use `$roundingMode` are divs, etc. If allow `$roundingMode` to be specified with add, intuitively it feels like the result of add will be rounded. > > Also, it is not possible to specify `$roundMode` in calculations using operators. > > However, if the user calculates two numbers with different rounding modes, and it is intentional rather than a mistake, I can't imagine what kind of result the user would want to get. Therefore, it may be better to make this an error. > > Is it appropriate to throw a value error in that case? I think making this an error would be appropriate. Generally speaking: Removing errors later is always possible if we find out that an operation is safe and well-defined. Adding an error if we find out that an operation is unsafe will result in breaking changes, thus we should get it right on the first try. Best regards Tim Düsterhus