PDA

View Full Version : FloatString Question



g3cwi
04-08-2012, 12:05 PM
I am attempting to use the StringToFloat method of FloatString. FloatString does not appear to need to be started and I have F32 running for other things and I am calling that for the maths in FloatString. It has been started in another object - but not in FloatString.

This very trivial test example fails despite trying various combinations with @.



tmp:= string("3.7")
debug.str(tmp) 'works fine
debug.nl
speed_dec := FS.StringToFloat(tmp) 'this line fails with tmp and @tmp
debug.str(string(" = ")) 'this never prints suggesting the line above causes a hang
debug.dec(speed_dec)


Ideas?

Regards

Richard

kuroneko
04-08-2012, 12:46 PM
Using the right version of FloatString (1.2) this works for me (using tmp). Note that the method returns a float which means that printing it as decimal isn't giving you the expected(?) result.

g3cwi
04-08-2012, 12:57 PM
Thanks Kuroneko. I am using v1.2. I note the point about the float but mine never gets to that statement. Very odd.

Cheers

Richard

kuroneko
04-08-2012, 01:03 PM
Can you attach the whole archive (PropTool: File->Archive) so I can (possibly) reproduce it here?

g3cwi
04-08-2012, 01:15 PM
Hi again

91484

The test snippet is just before the main loop (line 254).

Regards

Richard

kuroneko
04-08-2012, 01:32 PM
The difference is that my version used FloatMath yours is using F32. The latter requires initialisation (PASM cog) and therefore hangs during its first call (FFloat) while doing the conversion. Note that while you start the other copy of F32 this doesn't affect the version included by FloatString. I'd suggest you reinstate FloatMath given that string ops are slow'ish anyway and use F32 for the real stuff.

g3cwi
04-08-2012, 01:48 PM
Interesting.

I start F32 on line 142 of the main part of the program but as you say, that's not enough.I also tried an additional F32.Start at the first statement inside FloatString StringToFloat but it still failed.

Regards

Richard

kuroneko
04-08-2012, 01:59 PM
Works for me. I added an extra long on to the VAR section and these two lines at the beginning of the function:

ifnot on~~
f.start

Note that I cut down the example to just having the debug serial object and FloatString around. From the looks of it you're not running out of cogs either. Can you verify the result of the start method call?

g3cwi
04-08-2012, 02:43 PM
Hooray! All working now. That was a bit strange. Looks like I was on the right track for a while but my fix failed. Thanks again!

Regards

Richard

g3cwi
04-08-2012, 03:47 PM
Some really useful progress today. Many odd things I have noted are starting to become much clearer.

More beer needed.

Regards

Richard