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

From: Date: Wed, 27 Mar 2024 10:46:05 +0000
Subject: Re: [RFC] [Discussion] Support object type in BCMath
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-122775@lists.php.net to get a copy of this message
Hi Aleksander, > 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. Ah, that's right. I wonder why I forgot about method chaining. Update RFC. If we miss something and $scale is needed, I can always revert the RFC. > I'm not sure I like this. Maybe we should be more strict here and treat the $scale in > constructor (and later withScale()) as the actual scale for all operations. > > So, in the case above I'd expect ->scale to be 2, and ->value to be > '2.46'. If I wanted $num to have a scale that may change, I'd not define it in the > first place. Does that make sense? > > ps. that also means withScale(null) should be possible. I see, that may indeed make sense. Now here we have three choices about it. In fact, if want to behave like the current RFC, we can do it by calculating as $num + new Number($str). Yeah, I'll fix the RFC for this. Regards. Saki

« previous php.internals (#122775) next »