Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123021 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 AFDBC1A009C for ; Sun, 7 Apr 2024 18:02:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712513005; bh=mB2EL9DyO5rsfTMDt5MmJrx4kZiTu8y69Rn0EIoEW3Y=; h=Date:Subject:To:References:From:In-Reply-To:From; b=BMfDpn0B5bE4jJuKVuZVpj3/EUgopNbhPc0EXnIgk8K3u1Vn8S6A3w+YHdod+gDZr 0jDCdococB3xHk9udSLVQN4o7JwQM7lJueKCNB18BjMdij/1IMJifS2s8gM/nsZZrU tc14UlMxU7utCKGcKyFix9lXS6T8jDJ0N4GmJ9gDa+cm8zzkvFzkUXdSlP9oYV1Liy B+9aqxgTMLdVB+7MrrRDlFEqzIWGuJkugY7ls4R8Ofr/8wtxJ4IyWNObCu5w6qJ9+b 2TSBIk/66MiA99rUHqBPuLhmSL7A+zN4rJHb+J2gdYHs4yDeUl6gWfQOGFHOOZ5LlJ ECDLd2/xjGUSQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E02661804F7 for ; Sun, 7 Apr 2024 18:03:23 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, 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 fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 ; Sun, 7 Apr 2024 18:03:23 +0000 (UTC) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id A7A091380083 for ; Sun, 7 Apr 2024 14:02:51 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Sun, 07 Apr 2024 14:02:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1712512971; x=1712599371; bh=6hPLeI87KSmUXMJ1rsu+C4phFIdEbLF23HrsekzrLPE=; b= KucsUZV16F69u3Ps9aWicHEur2EFZ2uBkMRg5wxLUcge3M9N0TNidTf8uUIwAyng qA7CA6BuBNbkSOLTEW6friqz/lftXYMS5AjKnd8Fp/6o1W6pSRffr74ZGCjJjw6Y z2jpLhpg78Egv+itki3Z3sQdtU4VZe9sq/HD5KDwuxMPdaal7cJ7U9iH2aSr6tZC RAw81qHeTHh8jReAJ8JsXZojwJtW/tou0LFIxUYgrnwvMOA9ezKOOrPSSFBruWFA aOTQKM9xD0QGSC9zdDiNPjBPkuf5r3vSFmvgcHbwh3KvbZ44g5e4d561vDd1/2dl OB8ryjeA/DhRNWvtdslk6Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1712512971; x= 1712599371; bh=6hPLeI87KSmUXMJ1rsu+C4phFIdEbLF23HrsekzrLPE=; b=b AZ7cPEeSBLosP/G9RQJ3+9PgmSKeZllgp4DShPacwiRpC30xbUlxzJoJnKBaldkR xMfm51E18CczTmCWXY0Vfw2O2wtRm+Q6seOeeykbsx5YUfZo2OoQMKVb4rOGEm5x nPawFmSSp8TAgtA+K0q1A2LW3fHsWqBmhW/zzCTIEPwWvN1XLspBqFO3RR+lYC78 M7Um7aZbHfi+KqCB/QUW9xCka5U7KErhVfwRPa26c/8TLZuoBjW6kJOpBvye+sHV pOTjxdBbBAiB6v7BZ8GcKc6Efb3kqH0VJao1p12YMFsJjoYFGHDOg5CIRBaDAOR9 H93JENEHmSthpAAjanKwg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudeggedguddulecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesth ekredttddvjeenucfhrhhomhepfdftohifrghnucfvohhmmhhinhhsucglkffoufhorfgn fdcuoehimhhsohhprdhphhhpsehrfigvtgdrtghordhukheqnecuggftrfgrthhtvghrnh epffekveduffduvdehjedvfeekleeftddugeefheejudehgeeiudffgeeggeevfeehnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhmshhoph drphhhphesrhifvggtrdgtohdruhhk X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sun, 7 Apr 2024 14:02:50 -0400 (EDT) Message-ID: <738a8ceb-689c-454b-b4ea-d6ffc657cbce@rwec.co.uk> Date: Sun, 7 Apr 2024 19:02:47 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath To: internals@lists.php.net References: <959ccc6e-1d5c-48c0-9357-80e38becd1c5@bastelstu.be> Content-Language: en-GB In-Reply-To: <959ccc6e-1d5c-48c0-9357-80e38becd1c5@bastelstu.be> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 07/04/2024 18:09, Tim Düsterhus wrote: > - 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. Personally, I'm not a fan of setting the rounding mode and the "max expansion scale" on each instance, for the same reason I'm not keen on having the collation on each instance in Derick's Unicode string draft. I understand the temptation: specifying it for every operation makes code more verbose, particularly since it rules out use of $a / $b; while specifying it as a global or scoped option would make code harder to reason about. But I think carrying it around on the instance doesn't really solve either problem, and creates several new ones: - A program which wants all operations to use the same rounding system still has to specify the options every time it initialises a value, which is probably nearly as often as operating on them. - A program which wants different modes at different times will end up calling $foo->withRoundingMode(RoundingMode::HALF_UP)->div(2), which is more verbose and probably slower than $foo->div(2, RoundingMode::HALF_UP) - You can't look at a function accepting a Number as input and know what rounding mode it will operate in, unless it explicitly changes it. It would be easier to scan up to find a per-file / per-block declare() directive, than to trace the calling code to know the rounding mode of an instance. - A complex set of rules is invented to "prioritise" the options in operations like $a + $b. Or, that operation has to be forbidden unless the mode is consistent, at which point it might as well be a global setting. As a thought experiment for comparison, imagine if to sort an array numerically you had to write this: $array = array_set_sorting_mode($array, SORT_NUMERIC); $array = array_sort($array); Or worse, if you had to set it on each string: $array = array_map($array, fn($s) => $s->withSortingMode(SORT_NUMERIC)); $array = array_sort($array); Rather than (assuming we replaced the current by-reference sorts): $array = array_sort($array, SORT_NUMERIC); Because we're designing an object, attaching extra properties to it is easy, but I don't think it actually makes it easy to use. Regards, -- Rowan Tommins [IMSoP]