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 > printing an f32

#41899 - rize - Mon May 02, 2005 10:09 pm

I thought that there should be a function to help print f32's in a visible manner somewhere (since the consolePrintf won't take floats), but I didn't see one in the library.

If anyone needs to print an f32 you can print it in two parts like so:

Code:

int s = sqrtf32(intof32(2));         
consolePrintf("sqrtf32(2) = %d.%d", f32toint(s), f32fraction(s));

//f32toint is already in the library.

inline int f32fraction(f32 a)
{
   return (int)((a & 0x00000FFF)/0.4096);
}


It's not perfect and it could be faster, but it's not bad for debug.

#41957 - dovoto - Tue May 03, 2005 7:58 pm

Thats great. I was looking for an easy way to do that. I will try it out and add it to consolePrintf tonight. I allready have float support..it just does not work ;)
_________________
www.drunkencoders.com

#42143 - rize - Fri May 06, 2005 6:26 pm

yeah, I've noticed :)

still quite useful otherwise