Re: [RFC] Add "is_representable_as_float()" and "is_representable_as_int()" functions
| From: | Larry Garfield | Date: | Tue, 26 Aug 2025 14:48:40 +0000 |
| Subject: | Re: [RFC] Add "is_representable_as_float()" and "is_representable_as_int()" functions | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-128561@lists.php.net to get a copy of this message | ||
On Tue, Aug 26, 2025, at 9:30 AM, Tim Düsterhus wrote:
> For
is_representable_as_int() finding a reasonable definition
> is much
> easier, but I don't think I've ever had a use case where I needed to
> know whether a non-integer value is exactly representable as an int.
>
> Long story short: What actual real-world problem does this RFC attempt
> to solve? The list in the “Introduction” section is not particularly
> meaningful with regard to the real world and the JSON example is wrong
> as outlined above.
>
> Best regards
> Tim Düsterhus
I have multiple times just recently had need of "I have a numeric string, should I cast it to
an int or a float?", for which an is_representable_as_int() function (or similar) would be
quite helpful, and neater than the messy solution I usually use.
I haven't had a use for is_representable_as_float() that I can recall.
--Larry Garfield