Re: Proposal: Arbitrary precision native scalar type
| From: | Saki Takamachi | Date: | Sun, 07 Apr 2024 13:27:02 +0000 |
| Subject: | Re: Proposal: Arbitrary precision native scalar type | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-123012@lists.php.net to get a copy of this message | ||
Hi,
> What I'm saying is that $x / 2 doesn't have a good answer if $x is a fixed-precision
> number which can't be divided by 2 without exceeding that precision. You need a third operand,
> the rounding mode, so you can't write it as a binary operator, and need some kind of function
> like decimal_div(decimal $dividend, int|decimal $divisor, RoundingMode $roundingMode). How you
> implement "decimal" doesn't change that at all.
>
IMHO, if need a parameter that is anything other than a pure value, it's a bad fit for a native
type. It's just a different notation for creating instances.
If we really wanted decimal to be a native type, then the rounding mode and scale behavior should be
completely fixed and not user selectable. If not, decimal should be implemented as a class. In fact,
php's float will round values that are too fine, and cannot specify how it will round
them. (This involves CPU floating point modes, but I wanted to keep it consistent so I just gave it
as an example.)
Regards.
Saki