Re: [RFC] [Discussion] Support object type in BCMath

From: Date: Wed, 27 Mar 2024 06:34:44 +0000
Subject: Re: [RFC] [Discussion] Support object type in BCMath
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-122771@lists.php.net to get a copy of this message
On 27.03.2024 01:36, Saki Takamachi wrote:
On the other hand, if allow the calculation method to specify a scale, we can write it like this:
$num = new Number('1.23');
$num2 = new Number('4.56');

$result = $num->add($num2, 4);
$result->value; // '5.7900'
$result->scale; // 4
It's just one less line, but that's the only reason to support the $scale argument.
If you write it as: $result = $num->withScale(4)->add($num2); it's not an extra line anymore. I also think that withScale() use will be rare, as we have the scale in constructor. I think the intention is more clear here, and I think it applies to all cases you mentioned, including div or pow. If you know you need to change the scale just add ->withScale(X) before. -- Aleksander Machniak Kolab Groupware Developer [https://kolab.org] Roundcube Webmail Developer [https://roundcube.net] ---------------------------------------------------- PGP: 19359DC1 # Blog: https://kolabian.wordpress.com

« previous php.internals (#122771) next »