Bit twiddling question

Dennis E. Hamilton dennis.hamilton at acm.org
Thu Mar 9 16:07:52 UTC 2017



> -----Original Message-----
> From: owner-freebsd-numerics at freebsd.org [mailto:owner-freebsd-
> numerics at freebsd.org] On Behalf Of Steve Kargl
> Sent: Wednesday, March 8, 2017 23:53
> To: Bruce Evans <brde at optusnet.com.au>
> Cc: freebsd-numerics at freebsd.org
> Subject: Re: Bit twiddling question
> 
> On Thu, Mar 09, 2017 at 05:58:52PM +1100, Bruce Evans wrote:
> > On Wed, 8 Mar 2017, Steve Kargl wrote:
> >
> > > Suppose I have a float 'x' that I know is in the
> > > range 1 <= x <= 0x1p23 and I know that 'x' is
> > > integral, e.g., x = 12.000.  If I use GET_FLOAT_WORD
> > > from math_private.h, then x=12.000 maps to ix=0x41400000.
> > > Is there a bit twiddling method that I can apply to ix to
> > > unambiguously determine if x is even of odd?
> >
> > I don't know of any good method.
[orcmid] 

If you are certain about the pre-conditions holding absolutely, figure out the power of 2 *float* to add to your value, such that the binary point is forced to be at the low-order edge of the float word.  This might be a bit faster than casting your float to int directly.    

 - Dennis

[ ... ]



More information about the freebsd-numerics mailing list