Re: "Shifting" floating point numbers





Jordan Abel wrote On 03/21/06 15:51,:
On 2006-03-21, woessner@xxxxxxxxx <woessner@xxxxxxxxx> wrote:

Does anyone know of a fast way to multiply floating point numbers by
powers of two? Conceptually, all you need to do is add to the
mantissa. But can I write C code (or x86 assembly) to accomplish this
without a full-blown multiply?

For example, I'd like to be able to do the following very quickly:

double x;
double y;

x = 42.13;
y = (1 << 9) * x;

Thanks in advance,
Bill


y = scalbn(x,9);

ITYM:

#if FLT_RADIX == 2
y = scalbn(x, 9);
#else
y = ???;
#endif

I've already posted a candidate for "???", one that
eliminates the dependency on C99 and perhaps even
obviates the preprocessor gunk ...

--
Eric.Sosman@xxxxxxx

.



Relevant Pages

  • Re: "Shifting" floating point numbers
    ... powers of two? ... With IEEE floating point shifting the mantissa will not accomplish what ...
    (comp.lang.c)
  • Re: "Shifting" floating point numbers
    ... powers of two? ... mantissa. ... But can I write C code to accomplish this ... the float variable. ...
    (comp.lang.c)
  • Re: "Shifting" floating point numbers
    ... powers of two? ... mantissa. ... But can I write C code to accomplish this ... Finally, if all these options are exhausted, you'd best go with x86 assembler and read up on the format of double precision numbers. ...
    (comp.lang.c)
  • "Shifting" floating point numbers
    ... Does anyone know of a fast way to multiply floating point numbers by ... powers of two? ... mantissa. ... But can I write C code to accomplish this ...
    (comp.lang.c)
  • Re: "Shifting" floating point numbers
    ... powers of two? ... mantissa. ... A problem is in the position of the exponent in the double. ... FSCALE, that do just what you want, multiply very quickly by a power ...
    (comp.lang.c)