Re: [DISCUSSION] Adding the "is_integer_safe()" function
| From: | Alexandre Daubois | Date: | Sat, 26 Jul 2025 06:13:27 +0000 |
| Subject: | Re: [DISCUSSION] Adding the "is_integer_safe()" function | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-128234@lists.php.net to get a copy of this message | ||
Hello Rowan,
Le ven. 25 juil. 2025 à 23:10, Rowan Tommins [IMSoP]
<imsop.php@rwec.co.uk> a écrit :
> 1) You need to flesh out your proposal to be explicit about *what* it would do, as well as why.
Indeed, I was too focused on the why and I forgot the most important part.
The idea is to have a function that receives an integer or a float and
returns bool if the provided argument is inside the safe Javascript
integer interval, namely [-(2^53)+1 ; (2^53)-1]. It's signature would
be
is_integer_safe(int|float $num): bool. This interval is
considered safe because the floating-point mantissa is stored on 52
bits. This is nicely described in MDN [1].
> 2) The function needs a better name, to avoid confusion over what "safe" means.
I agree with you. I haven't come up with a better name yet as this one
could be ambiguous.
Best,
Alex
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER#description