Bit twiddling question
Steve Kargl
sgk at troutmask.apl.washington.edu
Thu Mar 9 15:35:25 UTC 2017
On Thu, Mar 09, 2017 at 07:23:07AM -0800, Steve Kargl wrote:
>
> if (ix < 0x43300000) { /* 1 <= |x| < 0x1p52 */
> double volatile vx;
> uint32_t n;
> vx = ax + 0x1p52;
> vx = vx - 0x1p52;
> if (vx == ax) return(0);
> if (vx > UINT32_MAX) { /* ax = m + n + r with m + n */
> vx -= UINT32_MAX; /* m = UINT32_MAX. n is in range */
> ax -= UINT32_MAX;
> }
> n = (uint32_t)vx;
> ax = __compute_sinpi(ax - n);
> if (n & 1) ax = -ax;
> return ((hx & 0x80000000) ? -ax : ax);
> }
>
We don't even need to use UINT32_MAX. We can do something
like
if (vx > 0x1p30) {
vx -= 0x1p30;
ax -= 0x1p30;
}
so there is no conversion from uint32_t to double. We also
probably want to minimize access to a volatile, so we would
have y = vx - 0x1p52 and use y afterwards.
--
Steve
20161221 https://www.youtube.com/watch?v=IbCHE-hONow
More information about the freebsd-numerics
mailing list