Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123076 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 DB0C81A009C for ; Tue, 9 Apr 2024 23:27:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712705265; bh=crWAWpHQJNIP5I5PBk6npC4sdrL2tvYGXiKIwEmgZuI=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=lFZs0ErkIxuAPE/Yt2saUs25rERsq/UAfohodCYf8UODmlZUzIuThXLkP37v+uTdG uVDTSmwB9R5pGk7th/Q+f/OUIZu5Q8VCOmaTCVS6jrzsf6IyL0IawdXWmzP66qA3d5 nYnz/YF+d5lfx4gtPq4nHAku+Qq7c5u2DipJUucnmKDISuELskds67hlspRJdLT+Iq 0ZvqEUx3gqojKclq8T6szGyzL2XxHXxp+O+JqQPeRJJYqspi9EObRtsHhaK8jVPIvj 2zDzY9yUpRcJEx39OFRFz6b8WHz+qSdMyzftJwAfKN0e0QbTMi0FoMZTJ30r46Upwt GsqZwcForLSJA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C5F53180562 for ; Tue, 9 Apr 2024 23:27:43 +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 mail.sakiot.com (mail.sakiot.com [160.16.227.216]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 9 Apr 2024 23:27:42 +0000 (UTC) Received: from smtpclient.apple (32.12.156.220.rev.vmobile.jp [220.156.12.32]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by mail.sakiot.com (Postfix) with ESMTPSA id 5ED1A401EE; Wed, 10 Apr 2024 08:27:07 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=sakiot.com; s=default; t=1712705227; bh=crWAWpHQJNIP5I5PBk6npC4sdrL2tvYGXiKIwEmgZuI=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=H6qaK0HqaBz8q5ANiXGXhJdDGbZ0TkI3jbTM9skCkLeO17NBd00pddKtT6r/enshM sVcoNWQ4jRMCDHuHi3HwABW3t1cTNsfcYuE5tv5e6YSieiMEejdMKRvpBXUIHKDED5 C5RT8gIG/gp1juU8sn/lla+s8HanCCEK5oT9P6ng= Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net Mime-Version: 1.0 (1.0) Subject: Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath Date: Wed, 10 Apr 2024 08:26:54 +0900 Message-ID: <9A85CC53-EFDB-4D14-99FB-ACFA4C6DBD09@sakiot.com> References: Cc: internals@lists.php.net In-Reply-To: To: =?utf-8?Q?Tim_D=C3=BCsterhus?= X-Mailer: iPhone Mail (21D61) From: saki@sakiot.com (Saki Takamachi) Hi Tim, > 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, pro= perties, and methods. It's currently split across multiple code blocks and t= he interfaces are missing entirely. >=20 > Example: >=20 > final readonly class Number implements \Stringable { > public string $value; > // Further properties omitted for brevity. >=20 > public function add(Number|string|int $num): Number {} > // Further methods omitted for brevity. > } Ah I see. I misunderstood. I will add it when the discussion is settled. >>> - I don't want to expand the scope of your RFC further than necessary, b= ut for the rounding mode, I wonder if we should first add the RoundingMode e= num 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::$ro= undMode` 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 discussi= on. I'd be happy to co-author it. >> Oh, that's a good idea. Makes sense. I think it would be simpler to prepa= re an RFC separate from this RFC, so I'm going to create one right away. Onc= e you have a certain amount of content, I would be happy if you could check i= t out and make corrections if necessary. >=20 > Sure, just send me an email and I'm happy to look over it before you put i= t up for discussion. Thanks! >>> - For `format()`, I'm not sure whether we should actually add the functi= on. While we have number_format() for regular numbers with the same signatur= e, 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 i= n 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 strin= g type number without converting it to a float? >=20 > It appears the underlying icu4c library supports formatting numeric string= s, yes: >=20 > https://unicode-org.github.io/icu-docs/apidoc/dev/icu4c/classicu_1_1Number= Format.html#a8ed2ca7b9a65bf08c4ef81bbf9680f0d What I meant was that there is currently no such function in PHP. Do you thi= nk I should propose adding it to this RFC? >>> - I'm not sure if the priority for the rounding modes is sound. My gut f= eeling 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 w= rong here. >> As mentioned in the RFC, the problem here is commutative calculations (ad= d, sub, mul). This means that even if specify `$roundingMode` during these c= alculations, `$roundingMode` will not be used in these calculations. Calcula= tions that use `$roundingMode` are divs, etc. If allow `$roundingMode` to be= specified with add, intuitively it feels like the result of add will be rou= nded. >> Also, it is not possible to specify `$roundMode` in calculations using op= erators. >> 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 r= esult the user would want to get. Therefore, it may be better to make this a= n error. >> Is it appropriate to throw a value error in that case? >=20 > I think making this an error would be appropriate. Generally speaking: Rem= oving errors later is always possible if we find out that an operation is sa= fe and well-defined. Adding an error if we find out that an operation is uns= afe will result in breaking changes, thus we should get it right on the firs= t try. I agree, but if we adopt Rowan's suggestion this issue will go away, so if t= he issue is still there when things calm down I'll add the error. Regards. Saki=