#include "game_types.h"

/* Float_Divide3 @ 0x0801E720 (real 52B) -- rounded divide of two stacked floats via sqrt path. Mirrors src/matched/Float_Divide3.c. */
/* Rounds both inputs, flips the divisor sign, and divides through the
   SqrtEstimate/Sqrt chain. Stack-frame sandwich; arities per the float-lib
   convention -- see src/matched twin. TODO(arity). */
extern void Float_Round(void *out, void *in);
extern void Float_SqrtEstimate(void *r, void *a, void *b);
extern int Float_Sqrt(int r);

int Float_Divide3(int a, int b)
{
    long long ra = a, rb = b, t1, t2[2];
    Float_Round(&ra, &ra);
    Float_Round(&rb, &rb);
    ((int *)&rb)[1] ^= 1;
    Float_SqrtEstimate(&t1, &rb, &t2);
    return Float_Sqrt((int)&t1);
}
