Re: [RFC] [Discussion] Rounding Integers as int
| From: | Derick Rethans | Date: | Wed, 27 Sep 2023 13:38:16 +0000 |
| Subject: | Re: [RFC] [Discussion] Rounding Integers as int | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-121153@lists.php.net to get a copy of this message | ||
On Tue, 26 Sep 2023, Larry Garfield wrote:
> 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.
They can't do that. ceil(2.4e102) can't be repesented as an integer.
> 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?
(float) $int *could* also do something:
$ php -dprecision=20 -r 'echo (float) 1152921504606846974;'
1152921504606846976
$ php -dprecision=20 -r 'var_dump(ceil((float) 1152921504606846974));'
double(1152921504606846976)
(see how the 74 changes into 76 at the end).
Integers in the ranges LONG_MAX to 2^53, and -2^53 to LONG_MIN can't be
represented as whole numbers as float, and some precision is lost.
cheers,
Derick