gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > simple floating point

#58390 - funkaster - Sun Oct 23, 2005 3:05 am

I need to perform a simple division (to measure a tangent), what types should I use?
for instance, this is the C code:

float tg;
tg = ((float)dx)/((float)dy);

I know the NDS doesn't have a FPU, but I read somewhere that it has some firmware division routines... How do I call them?
thanks a lot.

#58594 - dovoto - Mon Oct 24, 2005 7:44 pm

division operator is allready over-riden to use firmware divide. This does not help much with floating point operations though as it is integer only. DS also has a hardware integer division.

int32 div32(int32 num, int32 den)

To use with libnds.
_________________
www.drunkencoders.com

#58597 - SevenString - Mon Oct 24, 2005 7:58 pm

one method is to used fixed point values and call the divf32 inline function found in libgba/include/arm9/math.h

if you need both floating point input and output for the function, you could always do it like this:

Code:
// THESE TWO LINES FOUND IN videoGL.h, ARE SHOWN ONLY FOR CLARITY
#define floatof32(n)         ((f32)((n) * (1 << 12)))
#define f32tofloat(n)        (((float)(n)) / (float)(1<<12))

float result = f32tofloat(divf32(floatof32(numerator), floatof32(denominator)));

_________________
"Artificial Intelligence is no match for natural stupidity."