[PHP-DEV] BCMath: Supporting scientific notation

Hi all!

In the following issue, there was a proposal to add support for scientific notation in BCMath.

I agree with this and have already created a prototype.

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

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.
bcmath functions to support scientific notation numbers · Issue #17876 · php/php-src · GitHub

I agree with this and have already created a prototype.
ext/bcmath: Supports scientific notation by SakiTakamachi · Pull Request #18068 · php/php-src · GitHub

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