Duggle
February 19, 2012, 10:12am
1
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
T.K
February 19, 2012, 8:32pm
2
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.
Duggle
February 19, 2012, 10:59pm
3
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.