Shop OBEX P1 Docs P2 Docs Learn Events
FloatString Question — Parallax Forums

FloatString Question

g3cwig3cwi Posts: 262
edited 2012-04-08 07:47 in Propeller 1
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

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2012-04-08 04:46
    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.
  • g3cwig3cwi Posts: 262
    edited 2012-04-08 04:57
    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
  • kuronekokuroneko Posts: 3,623
    edited 2012-04-08 05:03
    Can you attach the whole archive (PropTool: File->Archive) so I can (possibly) reproduce it here?
  • g3cwig3cwi Posts: 262
    edited 2012-04-08 05:15
  • kuronekokuroneko Posts: 3,623
    edited 2012-04-08 05:32
    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.
  • g3cwig3cwi Posts: 262
    edited 2012-04-08 05:48
    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
  • kuronekokuroneko Posts: 3,623
    edited 2012-04-08 05:59
    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?
  • g3cwig3cwi Posts: 262
    edited 2012-04-08 06:43
    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
  • g3cwig3cwi Posts: 262
    edited 2012-04-08 07:47
    Some really useful progress today. Many odd things I have noted are starting to become much clearer.

    More beer needed.

    Regards

    Richard
Sign In or Register to comment.