Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 Mar 2017 07:35:23 -0800
From:      Steve Kargl <sgk@troutmask.apl.washington.edu>
To:        Bruce Evans <brde@optusnet.com.au>
Cc:        freebsd-numerics@freebsd.org
Subject:   Re: Bit twiddling question
Message-ID:  <20170309153523.GA33379@troutmask.apl.washington.edu>
In-Reply-To: <20170309152307.GA32781@troutmask.apl.washington.edu>
References:  <20170308202417.GA23103@troutmask.apl.washington.edu> <20170309173152.F1269@besplex.bde.org> <20170309075236.GA30199@troutmask.apl.washington.edu> <20170309152307.GA32781@troutmask.apl.washington.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170309153523.GA33379>