Re: Proposal: Arbitrary precision native scalar type
| From: | Derick Rethans | Date: | Tue, 09 Apr 2024 10:52:57 +0000 |
| Subject: | Re: Proposal: Arbitrary precision native scalar type | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-123053@lists.php.net to get a copy of this message | ||
On Thu, 7 Dec 2023, Alex Pravdin wrote:
> Accounting for all of the above, I suggest adding a native numeric
> scalar arbitrary precision type called "decimal". Below are the
> preliminary requirements for implementation.
Adding a new native type to PHP will create a large change. Not only is
it "just" adding a new native type, it also means all of the conversions
between types need to be added. This is not a small task.
> Decimal values can be created from literals by specifying a modifier or using
> the (decimal) typecast:
>
> $v = 0.2d;
> $v = (decimal) 0.2; // Creates a decimal value without intermediary float
>
> It uses the precision and scale defined in php.ini.
If you want to use arbitrary precision natives, then a precision and
scale as defined in php.ini defeats the purpose. Every installation can
then potentially calculate things in a different way.
The only way how to prevent that, is to have *actual* Decimal type, such
as the Decimal type in MongoDB uses (the IEEE 754 decimal128 type):
- https://www.mongodb.com/docs/mongodb-shell/reference/data-types/#std-label-shell-type-decimal
- https://en.wikipedia.org/wiki/Decimal128_floating-point_format
cheers,
Derick
--
https://derickrethans.nl | https://xdebug.org | https://dram.io
Author of Xdebug. Like it? Consider supporting me: https://xdebug.org/support
mastodon: @derickr@phpc.social @xdebug@phpc.social