Driver python expression doesn't work as intended (doesn't calculate if else properly)

I can't understand why it doesn't work. Driver value should be 0 according to my expression. Can't figure out what is wrong with it.

I wouldn't trust the value in a quaternion to exactly equal a whole number.

There are decimal numbers that a base two floating point number can't represent, for the same reason that you can't represent 1/3 exactly in base ten. While -1 isn't one of those numbers, it's conceivable and probably to be expected that some minute inaccuracy would have been introduced in producing the number that's used for that driver channel.

Try this:

0 if abs(-1-var) < 0.001 else 1

or

0 if var < -0.999 else

• Thanks! That's interesting, didn't know those "value" numbers might be rounded!
– Anna
Mar 19 '21 at 2:12
• math.isclose is also available 0 if isclose(var, -1) else 1 Mar 19 '21 at 2:42
• or since booleans convert to ints in drivers in this case could use 1 - isclose(var, -1) or not isclose(var, -1) Mar 19 '21 at 3:51
• It says "slow python expression" and refuses to execute it, so I guess no luck here
– Anna
Mar 19 '21 at 13:48
• @Anna Try to enable Auto Run Python Scripts in the Save & Load preferences Mar 19 '21 at 15:28