Skip to content

Rounding and Type Change methods #23

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
6 of 7 tasks
Lokathor opened this issue Oct 5, 2020 · 5 comments · Fixed by #34
Closed
6 of 7 tasks

Rounding and Type Change methods #23

Lokathor opened this issue Oct 5, 2020 · 5 comments · Fixed by #34
Assignees
Labels
C-feature-request Category: a feature request, i.e. not implemented / a PR C-tracking-issue Ongoing issue with checkboxes for partial progress and such

Comments

@Lokathor
Copy link
Contributor

Lokathor commented Oct 5, 2020

Before we can begin implementing a few of the more advanced functions, we'll need a few more of the basic utility functions for manipulating values.

For floats:

  • round to nearest whole number (output is the same float type)
  • ceiling / round to infinity
  • floor / round to negative infinity
  • truncate / round to zero
  • fraction (remove the whole-number part)
  • round to integer (output is the same-bit signed integer type)

For signed ints:

  • round to float (output is the same-bit float type)
@Lokathor Lokathor added C-tracking-issue Ongoing issue with checkboxes for partial progress and such C-feature-request Category: a feature request, i.e. not implemented / a PR labels Oct 5, 2020
@calebzulawski
Copy link
Member

Any idea what the type converting functions should be called? There doesn't seem to be an equivalent for f32 or f64...

@Lokathor
Copy link
Contributor Author

in wide i call them round and then round_int.

basically https://doc.rust-lang.org/core/arch/x86_64/fn._mm_cvtps_epi32.html

@calebzulawski
Copy link
Member

calebzulawski commented Oct 11, 2020

Probably relevant: https://doc.rust-lang.org/std/intrinsics/fn.float_to_int_unchecked.html

There actually is an equivalent in std but I missed it. This intrinsic should actually work on vectors as well.

@Lokathor
Copy link
Contributor Author

I think that cvtps_epi32 returns a value for any value, even if the value is not the same number. I think that nans produce i32::MIN or something like that.

I'd hate to add more ways to get undef, but i suppose it could be done if that's what the people clamor for.

@calebzulawski
Copy link
Member

Well, on a failure it raises a fp exception still (NEON's vcvt does this as well). I think the function should be unsafe because we the output is undefined on those lanes (but if we specify it's only undefined on those lanes, I think it's easy enough to use, even if it's unsafe?)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-feature-request Category: a feature request, i.e. not implemented / a PR C-tracking-issue Ongoing issue with checkboxes for partial progress and such
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants