Re: "Shifting" floating point numbers



In article <1142966759.446585.210770@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> woessner@xxxxxxxxx writes:
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;

With IEEE floating point shifting the mantissa will not accomplish what
you want. For instance, shifting the mantissa of 1.0 by any number of
bits will leave the value 1.0 because the mantissa (as a stored value)
is 0; there is an hidden (not stored) bit. When you want to multiply
by 2 you need to increment the exponent by 1.
--
*** t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~***/
.