|
![](/i/fill.gif) |
Nathan Kopp wrote:
> /*
> * This hex operation does a floor to next lower power of 2, by clearing
> * all of the mantissa bits. Works only on IEEE single precision floats
> */
[...]
> /*
> * This magic hex operation extracts the exponent, which gives us an
> * integer number suitable for labelling a range of a power of 2. In IEEE
> * format, value = pow(2,exponent-127). Therefore, if our index is, say,
> * 129, then the item has a maximum extent of (2 to the (129-127)), or
> * about 4 space units.
> */
[...]
> A portable version of these operations could be written, using logrithms and
> fractional powers, but it would be significantly slower.
These operations can be easily implemented using the standard C
functions ldexp and frexp, which should be reasonably fast (although
probably not as fast as the integer operations above) on any base2
system.
hp
--
_ | Peter J. Holzer | Think of it as evolution in action
|_|_) | Sysadmin WSR |
| | | hjp### [at] wsr ac at | -- Tony Rand in "Oath of Fealty"
__/ | http://wsrx.wsr.ac.at/~hjp/ | by Niven & Pournelle
Post a reply to this message
|
![](/i/fill.gif) |