Skip to content
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

test floating point casting better #1265

Merged
merged 3 commits into from
Mar 28, 2020
Merged

Conversation

RalfJung
Copy link
Member

No description provided.

Comment on lines 36 to 37
assert_eq!((u32::MAX-127) as f32 as u32, u32::MAX); // rounding loss
assert_eq!((u32::MAX-128) as f32 as u32, u32::MAX-255); // rounding loss
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hanna-kruppe do these two (and the two "rounding loss" tests below) look like correct behavior to you? I experimentally determined these to be the closest to u32::MAX where the output of the roundtrip cast changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jodysankey you also seem to know floating point encoding stuff quite well, would be nice if you could have a look.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they look exactly right to me. These are transition points from "odd significant + slightly less than 0.5 ULP" (which gets rounded down to uint::MAX - 1 ULP) to "odd significant + 0.5 ULP" (which is rounded up, so saturation kicks in when casting back to integer).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hanna-kruppe I only understood half of that, but that half sounds good. ;) Thanks!

@RalfJung
Copy link
Member Author

@bors r+

@bors
Copy link
Contributor

bors commented Mar 28, 2020

📌 Commit b8a817f has been approved by RalfJung

@bors
Copy link
Contributor

bors commented Mar 28, 2020

⌛ Testing commit b8a817f with merge fc30266...

@bors
Copy link
Contributor

bors commented Mar 28, 2020

☀️ Test successful - checks-travis, status-appveyor
Approved by: RalfJung
Pushing fc30266 to master...

@bors bors merged commit fc30266 into rust-lang:master Mar 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants