Sections
You are here: Home Forum Development Discussion Debug() float conversion?

Debug() float conversion?

Up to Development Discussion

Debug() float conversion?

Posted by Rick Mann at April 26. 2007
I'm trying to write some floating-point values, but calling Debug like this: Debug( 0, "angle %f", 1.234); Seems to crash things. Is this known to work?

Debug() float conversion?

Posted by Eric Whitefield at April 28. 2007
This may or may not be related, but you're not the first to have trouble with %f. However, it usually puts out garbage chars, not crashes everything. Unfortunately, my work around has been erased from the forum! So here you go. It could be written shorter but you get the idea. char[21] strTemp; snprintf(strTemp, 20, "%d.%02d", FloatRound(myfloat), FloatRemainder(myfloat)); int FloatRound(float VarValue) { int varRound = (int)VarValue; return varRound; } int FloatRemainder(float VarValue) { int varRound = (int)VarValue; int mask = varRound * 100; //shift two places with zeros in tens place float ftemp = VarValue * 100; //move decimal over because floats won't print int shifted = (int)ftemp; int remainder = shifted - mask; return remainder; }

Debug() float conversion?

Posted by Rob Talley at May 26. 2007
Has anyone run across the real fix to this problem?? I'm using (what I thought was the latest) GNUARM under windows. I know how to work around it but would be nice to be able to fix it. Thanks very much, Newbie Rob

Debug() float conversion?

Posted by Jim Long at June 05. 2007
sprinf with %f and/or %g give garbage as well jim

Debug() float conversion?

Posted by Eric Whitefield at June 18. 2007
Sure Rob, I can point you in the right direction of the real fix. It seems stdio in the GNU Toolchain has been compiled without floating point support. Common because many embedded systems don't support floating point. It would need to be compiled with FLOATING_POINT defined. jfaller seems to know a lot about it. As he points out the article is no longer entirely accurate. http://www.embedded.com/story/OEG20011220S0058 http://www.makingthings.com/forum/discussion/view_topic?topic_id=108 eDub

Re: Debug() float conversion?

Posted by Mike Bergen at March 09. 2010

Any ideas where this jewel ran off too?

 

Re: Debug() float conversion?

Posted by Fred at March 11. 2010

I am having this issue where I get garbage out from the float. Even when converting to a char array:

/debug/message È.V from USB (COM3)

 

Any help would be appreciated.

Re: Debug() float conversion?

Posted by Fred at March 15. 2010

I also get this through the USB Write command.

I am using the correct format for this too..    sprintf(cpos1, "%f", test1); //convert pos value to character array

 

Any idea how to print floats??

Re: Debug() float conversion?

Posted by Mike Bergen at March 15. 2010

See if this thread does anything for ya.  It fixed me right up. I had trouble finding it because I was looking for float. double/float same problem.

 

 Re: converting double to string

Powered by Ploneboard
Document Actions