Re: [RFC] [Discussion] Rounding Integers as int
| From: | Marc Bennewitz | Date: | Tue, 26 Sep 2023 20:16:30 +0000 |
| Subject: | Re: [RFC] [Discussion] Rounding Integers as int | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-121149@lists.php.net to get a copy of this message | ||
Hi Larry,
On 26.09.23 20:41, Larry Garfield wrote:
Attachment: [application/pgp-keys] OpenPGP public key OpenPGP_0x3936ABF753BC88CE.asc
Attachment: [application/pgp-signature] OpenPGP digital signature OpenPGP_signature.asc
On Tue, Sep 26, 2023, at 10:39 AM, Marc Bennewitz wrote: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?Hi internals I'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?
--Larry Garfield Marc
Attachment: [application/pgp-keys] OpenPGP public key OpenPGP_0x3936ABF753BC88CE.asc
Attachment: [application/pgp-signature] OpenPGP digital signature OpenPGP_signature.asc