Floating Point comparisons
RogerInHawaii
Posts: 87
Can you do "greater than" and "less than" comparisons with floating point numbers?
Is this valid?...
Is this valid?...
fpSomeNumber := 39.0 fpMinNumber := 12.0 fpMaxNumber := 100.0 NumIsGood := true if ((fpSomeNumber < fpMinNumber) OR (fpSomeNumber > fpMaxNumber)) NumIsGood := false
Comments
No, it's not. That will have the propeller performing operations on the 32 bit binary representation of those floats.
There are some comparison functions in the float32 library that will do what you require.
I spent about 25 minutes chasing a bug on Friday where I was scaling a reading from a sensor and the result was garbage. All my calcs were fixed point and simply scaled to get resolution, and I'd put 12.2 instead of 122 into one of the calculations. 12.2 == $41433333 so things went birko. Of course it's legal, so it compiled and ran. I've been meaning to have the compiler warn you when using a float number in a naked expression like that...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lt's not particularly silly, is it?
From memory, need to check, returns -1 if a < b, 0 if a = b and 1 if a > b
John Abshier