Re: "Shifting" floating point numbers
- From: "santosh" <santosh.k83@xxxxxxxxx>
- Date: 21 Mar 2006 10:53:57 -0800
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.
.
- References:
- "Shifting" floating point numbers
- From: woessner
- "Shifting" floating point numbers
- Prev by Date: Re: Benchmarking multiplications and additions
- Next by Date: Re: Array setup Question
- Previous by thread: "Shifting" floating point numbers
- Next by thread: Re: "Shifting" floating point numbers
- Index(es):
Relevant Pages
|