#42887 - blaisef01 - Mon May 16, 2005 4:15 am
I keep on getting wrong answers with sqrtf32 in the NDSLib
eg: sqrtf32(16384) = 5792 (sqrt(2) << 12)
when it should be 8192 (sqrt(4) << 12)
I tried replacing the function with this:
static inline f32 sqrtf32(f32 a)
{
SQRT_CR = SQRT_64;
while(SQRT_CR & SQRT_BUSY);
SQRT_PARAM64 = ((int64)a) << 13; // i changed this from 12
while(SQRT_CR & SQRT_BUSY);
return SQRT_RESULT32;
}
And everything seems to be okay. I don't quite understand why. If someone wants to explain it would be handy.
Cheers
eg: sqrtf32(16384) = 5792 (sqrt(2) << 12)
when it should be 8192 (sqrt(4) << 12)
I tried replacing the function with this:
static inline f32 sqrtf32(f32 a)
{
SQRT_CR = SQRT_64;
while(SQRT_CR & SQRT_BUSY);
SQRT_PARAM64 = ((int64)a) << 13; // i changed this from 12
while(SQRT_CR & SQRT_BUSY);
return SQRT_RESULT32;
}
And everything seems to be okay. I don't quite understand why. If someone wants to explain it would be handy.
Cheers