4

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.

  • The installation folder should have some header file with macro, type and constant declarations. – 0xC0000022L Jun 25 '18 at 8:25
4

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.

| improve this answer | |
0

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));
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.