-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
cgen: fix assert rvalue printing for float numbers #21538
Conversation
The problem with IEEE-754 floats is they are not guaranteed to be exact to any particular number of digits. Assert for floats will only ever accidentally match exactly. It might be better to simply not allow |
Maybe my example was not good. But the point is about the |
If |
Well, some people have hopes... the problem with allowing |
For example, a very simple test might always work... pub fn test_format() {
f := 0.2
assert f == 0.2
} However, if you did several calculations before the assert, you might instead end up with
|
I can work with a |
That would be fine, I suppose. The problem is that many (if not most) expect floats to act the same as ints (as in, precision the same, no round-off errors, etc.), but they don't. And when they don't, we get questions about why they don't. So letting them know up front that using |
I remember I wanted to ban Can't find it now. I think it makes sense. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work.
Fix #21536