Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // magic number is 2^n
- const double FMOD_MAGIC_NUMBER = 4294967296.0;
- const double FRAC_MAGIC_NUMBER = 268435456.0; // 2^28
- // these fmods won't work with negative numbers.
- // if the input is negative, the magic number needs to be negated,
- // but this support was omitted for speed.
- double fmod64(double f_)
- {
- M3Assert(0.0f <= f_ && f_ < FMOD_MAGIC_NUMBER);
- __m128d f = _mm_set_sd(f_);
- __m128d magic = _mm_set_sd(FMOD_MAGIC_NUMBER);
- f = _mm_add_sd(f, magic);
- // Hang on to the exponent, and to everything below 64.
- const M3uint64 mask_ = 0xFFF0000003FFFFFF;
- __m128d mask = _mm_set_sd(reinterpret_cast<const double&>(mask_));
- f = _mm_and_pd(f, mask);
- f = _mm_sub_sd(f, magic);
- _mm_store_sd(&f_, f);
- M3Assert(f.m128d_f64[0] < 64.0f);
- return f_;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement