-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Too big float
to int
cast results nonsense
#17081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
That's an implicit conversion. An explicit cast does not warn: https://3v4l.org/F9Ir7. Similarly implicitly converting this large In any case, given that this affects the core language functionality, this requires an RFC. |
As the first step of this/my feature request, I would expect The warning is second priority. |
Casting huge ints to floats also loses precision. Deciding what should warn and what shouldn't is not trivial. I also think this should be discussed first. |
In this issue I want to focus solely on https://3v4l.org/4gVYb behaviour which is very dangerous and not much expected from user POV. I would expect the resulting integer to be capped to |
float
to int
cast should emit warningfloat
to int
cast results nonsense
There has not been any recent activity in this feature request. It will automatically be closed in 14 days if no further action is taken. Please see https://github.com/probot/stale#is-closing-stale-issues-really-a-good-idea to understand why we auto-close stale feature requests. |
I belive this is manageable, where in the code the float to int is casted? I belive we should and can cap it to int max/min. |
There has not been any recent activity in this feature request. It will automatically be closed in 14 days if no further action is taken. Please see https://github.com/probot/stale#is-closing-stale-issues-really-a-good-idea to understand why we auto-close stale feature requests. |
Can someone please point me to the php-src file/line where the cast from float to int is done? |
Lines 130 to 140 in 4f0554f
|
So the case should be handled, but it isn't. Any idea why? Here is simpler repro: https://3v4l.org/JauAu -actual
+expected
9.2233720368548E+21
9223372036854775807
-0
+9223372036854775807 |
Ah because I pointed to the wrong location. |
Initially I opened this as a feature to get a warning emit. Let this issue be not about a warning, but about the result. Can this issue be please changed to a bug /wo RFC? I belive it is a bug because of these reasons:
|
It needs an RFC regardless because it changes behaviour that so long standing that people may (unknowingly) rely on it. I'm also quite certain that people will argue a lot about the desired behaviour. |
Description
repro: https://3v4l.org/0FJkO
I discovered this in library where big timeout was converted to milliseconds like
$timeoutFloat * 1000
and later casted into integer which resulted very dangerous0
without any warning.I would expect some warning like https://3v4l.org/4C3ru when too big float is impossible to be casted meaningfully into
int
.The text was updated successfully, but these errors were encountered: