Melchior FRANZ:
This patch fixes the sound of 737, Concorde and others, if fgfs was compiled with newer gcc versions (e.g. gcc 4.0.2). These compilers implement the c++ standard more strictly, and thus don't guarantee that c-style casted pointers to different data types really point to the same address. This is only guaranteed for union members.
This commit is contained in:
parent
75f817b39c
commit
606fc352aa
@ -51,16 +51,18 @@ void fast_BSR(float &x, register unsigned long shiftAmount);
|
|||||||
|
|
||||||
inline float fast_log2 (float val)
|
inline float fast_log2 (float val)
|
||||||
{
|
{
|
||||||
int * const exp_ptr = reinterpret_cast <int *> (&val);
|
union {
|
||||||
int x = *exp_ptr;
|
float f;
|
||||||
const int log_2 = ((x >> 23) & 255) - 128;
|
int i;
|
||||||
x &= ~(255 << 23);
|
} v;
|
||||||
x += 127 << 23;
|
v.f = val;
|
||||||
*exp_ptr = x;
|
const int log_2 = ((v.i >> 23) & 255) - 128;
|
||||||
|
v.i &= ~(255 << 23);
|
||||||
|
v.i += 127 << 23;
|
||||||
|
|
||||||
val = ((-1.0f/3) * val + 2) * val - 2.0f/3; // (1)
|
v.f = ((-1.0f/3) * v.f + 2) * v.f - 2.0f/3; // (1)
|
||||||
|
|
||||||
return (val + log_2);
|
return (v.f + log_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user