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
MathUtil: Add SaturatingCast to cast floats more safely #9480
Conversation
|
Could you remove this in favor of the new dolphin/Source/Core/DiscIO/WIACompression.cpp Lines 169 to 172 in 3e66db2
|
55005cc
to
d9c9571
Compare
|
@JosJuice Done. The tests also pass now; apparently using std::clamp was not a good idea because it forces |
returns 4294967295 instead of 0, which I don't think is intended. |
|
@Dentomologist |
d9c9571
to
7ba3a87
Compare
7ba3a87
to
6deffb5
Compare
65fcf08
to
efa7b49
Compare
efa7b49
to
7628397
Compare
| if (value < 0) | ||
| return lo; |
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.
I feel like there should be a static_assert(lo == 0) or something like that here.
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.
Or perhaps replace return lo; with return 0;? What do you think would be clearer?
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.
I personally think the static_assert would be clearer, since it makes the u32(...) < 0 assumption more explicit.
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.
Works for me
7628397
to
616fc47
Compare
09682dc
to
5c2b9fb
Compare
[conv.fpint]/1: > A prvalue of a floating-point type can be converted to a prvalue of > an integer type. The conversion truncates; that is, the fractional > part is discarded. The behavior is undefined if the truncated value > cannot be represented in the destination type.
5c2b9fb
to
1a9e72c
Compare
A modified version of #8871 with the clamp function added to MathUtil along with tests.
The second commit makes VertexLoaderTest use it in order to avoid undefined behavior: