-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
change int(::Float64) to error on non-integral values #6211
Comments
Perhaps the Noteworthy Differences from Other Languages section of the manual? |
Ah, yes. I was wondering where that section had gone. We should probably have a C section in there. |
See also #5413. |
I also think Wouldn't throwing an exception be a major speed bump for such a simple function? |
I've encountered numerous people coming from static languages who were very surprised that we (a) don't do integer division and (b) do rounding instead of truncation. My justifications are weak. People do, however, seem to agree that requiring the programmer to be explicit about how they want to convert to integers is ok. |
Making things unsurprising to people used to static languages doesn't seem like the right standard at this point. |
Integer division is just so annoying in python. I regularly waste 30 minutes before realising that both my variables happened to be integers. I don't have a strong opinion on the rounding vs truncation, but rounding is definitely less surprising. |
We have |
My feeling is that whenever you have more than one ways to define something and none is "obviously more correct" than others, then we should just don't allow that and tell people to articulate what they want explicitly. |
I think the real goal is to get rid of the |
@JeffBezanson I agree with this plan. |
Excellent, we all agree. |
I realized there is an important connection between
This works because So I would say if |
I've come to be in favor of both changes. The connection is interesting. It means that we can't make one change without the other. |
@jakebolewski points out that now we can do |
We've discussed this before and I think it's a good change. This forces people to be explicit about whether they want rounding, truncation, or whatever. The current behavior is a gotcha for people coming from C. Related to which, do we have a document somewhere for people coming from C where we can mention that int/int = float, since that is a surprise when coming from a static language?
The text was updated successfully, but these errors were encountered: