BCMath: Supporting scientific notation

php.internals

Saki Takamachi

1 year ago
Hi all! In the following issue, there was a proposal to add support for scientific notation in BCMath. https://github.com/php/php-src/issues/17876 I agree with this and have already created a prototype. https://github.com/php/php-src/pull/18068 The prototype allows to pass scientific notation values ​​to both functions and classes in the same way as normal numeric string. The Number class could add a method to convert strings to scientific notation, or it could simply not accept scientific notation in the constructor and create a dedicated static method for it. We can also choose not to accept scientific notation in BCMath functions. Could you please give your opinion on this? Regards, Saki

Christoph Becker

1 year ago
On 15.03.2025 at 01:14, Saki Takamachi wrote:
> In the following issue, there was a proposal to add support for scientific notation in BCMath. > https://github.com/php/php-src/issues/17876 > > I agree with this and have already created a prototype. > https://github.com/php/php-src/pull/18068 > > The prototype allows to pass scientific notation values ​​to both functions and classes in the same way as normal numeric string. > > The Number class could add a method to convert strings to scientific notation, or it could simply not accept scientific notation in the constructor and create a dedicated static method for it. > We can also choose not to accept scientific notation in BCMath functions. > > Could you please give your opinion on this?
The only problem I see with this is that users might now cast (almost) arbitrary float values to string, and pass these to BCMath. However, they can already do that for many float values, so probably not a big problem. Christoph