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

docs for to_int_unchecked should mention the safe version #244

Closed
Lokathor opened this issue Feb 9, 2022 · 3 comments · Fixed by #245
Closed

docs for to_int_unchecked should mention the safe version #244

Lokathor opened this issue Feb 9, 2022 · 3 comments · Fixed by #245

Comments

@Lokathor
Copy link
Contributor

Lokathor commented Feb 9, 2022

The docs for to_int_unchecked should mention that round is the safe version of the function.

@programmerjake
Copy link
Member

uuh, round isn't the safe version of to_int_unchecked:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a68ddebbf0e80e37bf027ff5d2738350

[src/main.rs:2] unsafe { 1.7f32.to_int_unchecked() } = 1
[src/main.rs:3] 1.7f32.round() = 2.0
[src/main.rs:4] 1.7f32 as i32 = 1

@Lokathor
Copy link
Contributor Author

Lokathor commented Feb 9, 2022

ah, so it's a truncate

@workingjubilee
Copy link
Member

workingjubilee commented Feb 9, 2022

Yes, roughly following cvttps2dq for the obvious cast of Simd::<f32, N>::to_int_unchecked::<i32>(self) -> Simd<i32, N>. Simd::cast::<i32>(self) will exhibit the correct safe behavior most of the time. It is completely reasonable for us to mention the safe function.

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 a pull request may close this issue.

3 participants