|
|
Nieminen Juha <war### [at] sarakerttunencstutfi> wrote...
> Nathan Kopp <Nat### [at] koppcom> wrote:
> : * PORTABILITY WARNING: this function REQUIRES IEEE single precision
> : floating
> : * point format to work.
>
> Why?
Later in the code you'll run across these two cryptic operations and
comments that describe them.
First,
/*
* 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
*/
convert.f = maxdel;
convert.l &= 0xff800000;
bsized = (DBL) convert.f;
And later,
/*
* 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.
*/
convert.f = (float) bsized;
base_id.Size = (convert.l & 0x7f800000) >> 23;
The variable "convert" is defined as follows:
union
{
float f;
long l;
}
convert;
A portable version of these operations could be written, using logrithms and
fractional powers, but it would be significantly slower. I suggest #ifdef
blocks so that VAX and other non-IEEE-compliant systems will be able to run
this code, even if it does have to run slowly.
-Nathan
Post a reply to this message
|
|