Shop OBEX P1 Docs P2 Docs Learn Events
Floating Point Support — Parallax Forums

Floating Point Support

kt88seampkt88seamp Posts: 112
edited 2010-02-12 00:00 in Propeller 1
I heard the prop has limited floating point support. I know passing parameters does not work, but what about something like this:

PUB SquareRoot | result, a

a := 2
result ^^= a

This in real life should return about 1.414. Does the prop store this as a floating point or does it round it to the nearest integer?

·

Comments

  • Graham StablerGraham Stabler Posts: 2,510
    edited 2010-02-11 22:49
    It will only do a proper floating point square root on a constant assignment I think.

    If you really need floating point functions you will need to use an object.

    However if you just want to ensure you don't loose your 414 then just represent 2 as 2000 and your result will be 1414.

    Graham

    p.s. I think you have to do result := ^^a
  • Mike GreenMike Green Posts: 23,101
    edited 2010-02-12 00:00
    The Propeller Tool does have floating point support, for constants and constant expressions only. There is an object in the Object Exchange that provides excellent single precision floating point support at run time, but the Propeller Tool does not generate code to call it. You have to write all floating point operations as function calls. You also have to write any floating point constants with a decimal point so the Propeller Tool knows they're floating point. There's a user's guide included in the download from the Object Exchange.
Sign In or Register to comment.