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