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

Float Question

CannibalRoboticsCannibalRobotics Posts: 535
edited 2010-12-08 11:02 in Propeller 1
Why does:

TimeZone := f.Ftrunc(f.div(Lon,15.0))

give me the result: -6.085645e+38 when sent to debug with

debug.str(fs.FloatToString(TimeZone))

'Lon' has been set up as a floating point value via FFloat() and is correctly displayed as -97 with

debug.str(fs.FloatToString(Lon))

The -6 part is correct but neither FRound or FTrunc seem to work at 'intgerizing'.
I'm missing something...

Comments

  • John AbshierJohn Abshier Posts: 1,116
    edited 2010-12-08 09:11
    TimeZone is an integer.
    Replace debug.str(fs.FloatToString(Lon)) with debug.dec(TimeZone)

    John Abshier
  • CannibalRoboticsCannibalRobotics Posts: 535
    edited 2010-12-08 10:11
    Well, hum.
    It's interesting that fRound and fTrunc return integers but all of the other functions return float's,,, I guess - it does leave me wanting a better documentation reference to the Float32 routines.
    Any suggestions? I looked at Cam's write up and it's great on time and space but still does not say much for specific call functionality.
    Thanks in advance.
  • lonesocklonesock Posts: 917
    edited 2010-12-08 10:15
    If you want it returned as a float, I added a "FloatTrunc" function to F32 (see my sig). The documentation is different, though I wouldn't necessarily say "better" [8^).

    Jonathan
  • Mike GreenMike Green Posts: 23,101
    edited 2010-12-08 11:02
    fRound and fTrunc are specific conversion routines for floating point to integer just like fFloat goes from integer to floating point. There happen to be two separate calls because they are two commonly used choices of what to do with the fractional part of the floating point number, round to the nearest integer or truncate the fraction. They probably didn't get much coverage in the documentation because they're so common in floating point libraries and instruction sets.
Sign In or Register to comment.