Re: [RFC] [Discussion] Allow int type argument to BCMath function

From: Date: Tue, 09 Jul 2024 17:47:55 +0000
Subject: Re: [RFC] [Discussion] Allow int type argument to BCMath function
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hi

On 7/8/24 11:36, Jordan LeDoux wrote:
I suspected the same thing when I was doing my arbitrary precision library, but I actually have yet to find a test case in all my unit tests where this happens when converting to a string. You can see this here: https://3v4l.org/Ud8Cn
PHP emits the shortest possible representation that roundtrips, so the precision loss indeed does not happen when converting from float, but rather when converting to float / when the implicit rounding happens during the calculation. Nevertheless the inherent rounding error of floats and an arbitrary precision maths library do not mix: Users should not be encouraged to mindlessly pass a float, but rather work with strings all the time or explicitly perform the necessary conversion as appropriate for their use case - which of course is easier with strict_types enabled because then the conversion would need to be made explicit with a cast. Best regards Tim Düsterhus

Thread (12 messages)

« previous php.internals (#124314) next »