Duggle Posted February 19, 2012 Report Share Posted February 19, 2012 I need to display floating point variables as I am experimenting with sensors of different kinds. I find sprintf() is not formatting float types. Is there a switch somewhere that controls the compile of stdio.h functions to include a full featured string formatter library? Also is floating point math fully supported by default? thanks Quote Link to comment Share on other sites More sharing options...
TK. Posted February 19, 2012 Report Share Posted February 19, 2012 Floating point math is fully supported (libm is included) But you don't really want to use the original printf() routine - it requires liba for functions like _read, _write, _sbrk, etc... and as far as I remember, later it will ask for libos as well. Thats unnecessary overhead (+ some implementation effort for the missing functions). If you want to try to get it running: disable all functions in http://svnmios.midibox.org/filedetails.php?repname=svn.mios32&path=%2Ftrunk%2Fmios32%2Fcommon%2Fprintf-stdarg.c Alternatively add the code for %f to the print() replacement Or just do the conversion in your application, e.g.: MIOS32_MIDI_SendDebugMessage("%d.%03d\n", (int)value, (int)(1000*value)%1000); [/code] Best Regards, Thorsten. Quote Link to comment Share on other sites More sharing options...
Duggle Posted February 19, 2012 Author Report Share Posted February 19, 2012 Works well, thanks TK! Oh, and if negative numbers are possible use:MIOS32_MIDI_SendDebugMessage("%d.%03d\n", (int)value, abs((int)(1000*value)%1000)); otherwise you get a negative symbol appearing in the fraction part. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.