Bit twiddling question
sgk at troutmask.apl.washington.edu
Thu Mar 9 16:48:08 UTC 2017
On Thu, Mar 09, 2017 at 08:07:37AM -0800, Dennis E. Hamilton wrote:
> > -----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.
> 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.
Thanks, I'll look into doing the above. Yes, I'm certain
of the conditions. See my other posts from earlier today.
I have a way forward. Optimizations can come later.
More information about the freebsd-numerics