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

From: Date: Mon, 08 Jul 2024 09:36:28 +0000
Subject: Re: [RFC] [Discussion] Allow int type argument to BCMath function
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On Sun, Jul 7, 2024 at 8:19 PM Saki Takamachi <[email protected]> wrote:

> Hi Juliette,
>
> > Hi Saki,
> >
> > Just wondering: why int|string instead of float|string ?
> > In my experience, floats are the more pertinent type for which to use
> the BCMath extension.
> >
> > Smile,
> > Juliette
>
> Since floating point numbers always contain a certain amount of error, I
> believe that they are not suitable as arguments for BCMath.
>
> For example, 0.285 becomes 0.284999... in floating point. From the
> perspective of arbitrary precision math, there is no universally agreeable
> way to properly handle values like this: there will always be people who
> want to treat it as 0.285, and people who want to treat it as 0.284999.....
>
> Therefore, I believe BCMath should not accept floats as arguments.
>
> Regards,
>
> Saki


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

Jordan


Thread (12 messages)

« previous php.internals (#124282) next »