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

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to