#include "game_types.h"

/* Bignum_InitFromFloat @ 0x0801D168 (real 76B) -- float-word to (lo, hi) pair. Mirrors src/matched/Bignum_InitFromFloat.c. */
/* Splits the float word: large biased exponents return (t, 0); otherwise
   derives the shift from the negated sum with the 19/20/30 cutoffs. Returns
   the (lo, hi) register pair as one long long. */
long long Bignum_InitFromFloat(int x)
{
    int t = (x & 0x7FF00000) + (int)0xFCC00000;
    unsigned lo, hi;
    if (t > 0) {
        lo = (unsigned)t;
        hi = 0;
    } else {
        int e = (unsigned)(-(unsigned)t) >> 20;
        if (e > 19) {
            hi = 0;
            e -= 20;
            lo = e > 30 ? 1u : 1u << (31 - e);
        } else {
            hi = 0x80000u >> e;
            lo = 0;
        }
    }
    return ((unsigned long long)hi << 32) | lo;
}
