what is COERCE_FLOAT in ida Hex-Rays' C++ pseudocode?

2018-06-22 15:00:20

I was reversing and then i've found a definition as COERCE_FLOAT:

float v28;

float v29;

v29 = COERCE_FLOAT(&v30);

v28 = COERCE_FLOAT(&v31); // what is this?

I've searched and

found that it was a simple casting method, but really like it would be in C++?

the value of v30 pass to v29 without the pointer? i don't understand.

I assume it's just a simple cast.

v29 = *reinterpret_cast< float* >( &v30 );

It would be easier if you'd share the generated assembly instead of the pseudo code.

It's probably just a simple cast like WasserEsser said. I encountered this same type of cast while trying to decompile the q_rsqrt function. You could probably recreate the same type of behaviour by using an cast, like WasserEsser suggested, but you could probably also use an union, like in this code :

float Q_rsqrt( float number )

{

union {

float f;

uint32_t i;

} conv;

float x2;

const float threehalfs = 1.5F;

x2 = number * 0.5F;

c

  • I assume it's just a simple cast.

    v29 = *reinterpret_cast< float* >( &v30 );

    It would be easier if you'd share the generated assembly instead of the pseudo code.

    2018-06-22 15:36:20
  • It's probably just a simple cast like WasserEsser said. I encountered this same type of cast while trying to decompile the q_rsqrt function. You could probably recreate the same type of behaviour by using an cast, like WasserEsser suggested, but you could probably also use an union, like in this code :

    float Q_rsqrt( float number )

    {

    union {

    float f;

    uint32_t i;

    } conv;

    float x2;

    const float threehalfs = 1.5F;

    x2 = number * 0.5F;

    conv.f = number;

    conv.i = 0x5f3759df - ( conv.i >> 1 );

    conv.f = conv.f * ( threehalfs - ( x2 * conv.f * conv.f ) );

    return conv.f;

    }

    Which then decompiles to this :

    float __stdcall Q_rsqrt(float a1)

    {

    return (flt1Point5

    - a1

    * flt0Point5

    * COERCE_FLOAT(0x5F3759DF - (SLODWORD(a1) >> 1))

    * COERCE_FLOAT(0x5F3759DF - (SLODWORD(a1) >> 1)))

    * COERCE_FLOAT(0x5F3759DF - (SLODWORD(a1) >> 1));

    }

    2018-06-22 15:54:19