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

Add XMVectorRound half away from zero alternative #39

Open
walbourn opened this issue Oct 25, 2016 · 2 comments
Open

Add XMVectorRound half away from zero alternative #39

walbourn opened this issue Oct 25, 2016 · 2 comments
Labels

Comments

@walbourn
Copy link
Member

walbourn commented Oct 25, 2016

The current XMVectorRound uses round-to-nearest (even) a.k.a. banker's rounding. This matches the implementation of the _mm_round_ps (SSE4) and vrndnq_f32 (ARMv8 NEON) intrinsics rounding behavior, so it can be implemented in a single instruction.

Many users, however, expect it to match roundf which C99 defines as handling half-way values by rounding away from zero a.k.a. commercial rounding. It might therefore be useful to provide an alternative version of XMVectorRound that supports half away-from-zero rounding instead of round-to-nearest (even).

See Wikipedia

@walbourn walbourn changed the title Add XMVectorRound away from zero alternative Add XMVectorRound half away from zero alternative Oct 25, 2016
@nfrechette
Copy link
Contributor

This is also called symmetric rounding.

  • 0.5 -> 1.0
  • -0.5 -> -1.0

@walbourn
Copy link
Member Author

walbourn commented Oct 29, 2021

Should be implementable using the existing floor and ceil implementations with some extra selection.

float roundf(float x) { return signbit(x) ? ceil(x - 0.5) : floor(x + 0.5); }

For ARMv8 / ARM64, vrndaq_f32 should do the equivalent of roundf.

@walbourn walbourn self-assigned this Oct 29, 2021
@walbourn walbourn pinned this issue Oct 29, 2021
@walbourn walbourn unpinned this issue Jan 17, 2022
@walbourn walbourn removed their assignment Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants