Re: [DISCUSSION] Adding the "is_integer_safe()" function

From: Date: Mon, 28 Jul 2025 13:04:01 +0000
Subject: Re: [DISCUSSION] Adding the "is_integer_safe()" function
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-128259@lists.php.net to get a copy of this message
Le lun. 28 juil. 2025 à 12:18, Claude Pache <claude.pache@gmail.com> a écrit : > This is not correct: 2**53 + 1 is perfectly “safe” (for 64-bit builds of PHP), see: > https://3v4l.org/P939d > > The specific notion of “safe integer” as introduced in JavaScript makes sense only for > numbers encoded using IEEE 754, which is what PHP uses for float. In > PHP, there is a specialised type for integers, so that the need of such a function is not clear, > because every integer encoded as int is “safe”. Or maybe you > want something like is_safe_integer_when_interpreted_as_float()? > > Also, note that the particular Symfony example given at the beginning of this thread uses a > function that expects a string, not an int or a float. In that example, something like I­õ§ìö�ð > 1^z5is_numeric_value_producing_exact_integer_when_interpreted_as_float() could > have been useful, but this use case is very specialised. > > —Claude Right! I think we found Gina proposed a nice alternative. I wrote a few specs in my last thread message in response to Gina. Please let me know if there's something that is unclear or bothering you. Best, Alexandre Daubois

« previous php.internals (#128259) next »