Hi Larry, On 26.09.23 20:41, Larry Garfield wrote:
On Tue, Sep 26, 2023, at 10:39 AM, Marc Bennewitz wrote:Hi internalsI'd like to put a new RFC under discussion: https://wiki.php.net/rfc/integer-rounding Best, MarcI'm honestly kind of confused by this. The basic concept, as I understand it, is sound. But the rest of the description seems to suggest that the returned type will depend on the passed-in type? That makes little sense to me. Since we already know that int is contravariant to float, I would expect round to return int if it can, float if there is a decimal precision set. ceil and floor should always return ints, unconditionally, because that's literally what their purpose is. But that RFC doesn't say that, which makes me quite confused. Similarly, the BC shim would therefore be (float)ceil($x), not ceil((float)$x), which... I don't think that would even do anything, would it?
Currently, all three functions return float, no matter what. This is an implicit cast and results in inaccurate values for numbers above 2^53. The RFC proposes to keep the given type if possible.
Given that, the return value is (and was) guaranteed to be float if the given number is float.
If the given number is int the return value will most likely be int except in case of integer over- / underflow.
If instead all integers would be returned as int-type, we would have additional issues...
* additional BC due to additional implicit cast from float to int * less accuracy on 32bit platforms (numbers > 2^31) * what to do on integer overflow?
--Larry Garfield
Marc
OpenPGP_0x3936ABF753BC88CE.asc
Description: OpenPGP public key
OpenPGP_signature
Description: OpenPGP digital signature