Shop OBEX P1 Docs P2 Docs Learn Events
Printing out Floating Numbers — Parallax Forums

Printing out Floating Numbers

Technic-R-CTechnic-R-C Posts: 117
edited 2010-07-08 19:19 in Propeller 1
hello, I am having trouble printing out floating point calculations to the Parallax serial terminal and I was wondering if any of you folks could help me out.

CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000
OBJ
 
  Debug   : "FullDuplexSerialPlus"
  fMath   : "Float32"
  fString : "FloatString"
 
PUB Convert | a, b, c, d
 
  Debug.StartPST(19200)
  waitcnt(clkfreq*2 + cnt)
  Debug.tx(Debug#CLS)
  a := 21.622
  b := 80_000
  
  'WORKS BELOW
  Debug.str(String(" a: "))
  Debug.str(fstring.FloatToString(a))
  Debug.str(String(" b: ")) 
  Debug.dec(b)
 
 
  'DOES NOT WORK BELOW
  c := fMath.FMul(a, 32)
  d := fMath.FAdd(c, b)
  
  Debug.str(String(" c: "))
  Debug.str(fstring.FloatToString(c))
  Debug.str(String(" d: "))    
  Debug.str(fstring.FloatToString(d))



The output of this code to the Parallax serial terminal is:
a: 21.622 b: 80000

·with nothing afterwards as if the program stopped after
c := fMath.FMul(a, 32)

All help is appreciated.

Thank you

Technic-R-C

Comments

  • Technic-R-CTechnic-R-C Posts: 117
    edited 2010-07-08 19:12
    Ok I forgot one simple call of "fMath.start" but I am recieving very strange values out of the propeller serial terminal.
    They are as follows:
    c: 9.68272e-43 d: 1.130722e-40
    
    

    ·These aren't correct.. I'll keep trying but if anyone could help out it'd be appreciated.

    Technic-R-C
  • Technic-R-CTechnic-R-C Posts: 117
    edited 2010-07-08 19:17
    Figured it out.

    you have to set

    b := to 80_000.0
    

    and then

    c := fMath.FMul(a, 32.0)
    

    Problem solved.· I scratched my head for two days but figured it out within seconds of posting it on this forum.· Forum moderators please feel free to delete this thread.

    Thanks

    Technic-R-C
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-07-08 19:19
    I haven't used floating point much, but I thing the problem is in your c := fMath.FMul(a, 32) statment.· The number "32" is an integer that is being treated as a floating point number.· This would represent an extremely small floating point number, which is why you are getting a value with a -40 exponent.· Use 32.0 and it should work.
Sign In or Register to comment.