Re: "Shifting" floating point numbers



woess...@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;

If you know the floating point representation of your implementation
and underlying hardware, you can copy the float value to an unsiged
long variable, shift the appropriate bits and copy the value back to
the float variable. All this implies that you'll have to know details
about your implementation and thus risk losing some portability.

These days, FPU's are quite fast, so a direct multiply on the float
should be efficient enough unless you're code is time critical.

.



Relevant Pages

  • Re: "Shifting" floating point numbers
    ... powers of two? ... mantissa. ... But can I write C code to accomplish this ... obviates the preprocessor gunk ... ...
    (comp.lang.c)
  • 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 ... 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: Converting bits to FLOAT
    ... > FLOAT object? ... (incf exponent (byte-size mantissa-byte)) ... (defun scale (mantissa exponent mantissa-bits) ...
    (comp.lang.lisp)