Shop OBEX P1 Docs P2 Docs Learn Events
Using real numbers in if comparisons question — Parallax Forums

Using real numbers in if comparisons question

Thomas FletcherThomas Fletcher Posts: 91
edited 2009-03-09 19:57 in Propeller 1
x:=1
degree := -100.35

if degree < -8.05
x:=2

The result of the code above should be x=2, but I get x=1 and
if I make degree = -5 then I get x=2 even though that is wrong.

How do you compare real numbers with the propeller?

Is anybody working on a way to use math co-processor chips with the propeller?

Comments

  • BasilBasil Posts: 380
    edited 2009-03-09 02:32
    Hi Thomas,

    Have a look at the floating point math object in the obex [noparse]:)[/noparse] There is a compare function.

    EDIT: obex.parallax.com/objects/202/ here it is [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    Velden in N scale
  • Thomas FletcherThomas Fletcher Posts: 91
    edited 2009-03-09 12:31
    How is the compare function used? I can make out that it takes two variables. What does it return? How is it used to determine if a variable is greater or lessor then other variable?
  • Thomas FletcherThomas Fletcher Posts: 91
    edited 2009-03-09 12:38
    I think I get it now.

    f32.fcmp(x,y)

    1: x>y
    0: x==y
    -1: x<y
  • BasilBasil Posts: 380
    edited 2009-03-09 19:57
    Sorry for the slow reply! Looks like you got it though [noparse]:)[/noparse] Does that do what you need?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    Velden in N scale
Sign In or Register to comment.