Josh wrote:For me, zero is #False and everything else is #True
No, strictly speaking, in Boolean algebra True is True and False is False, and neither is a number. But when programming, just like integers and floats these values get 'cast' into binary which can be stored in a register.
Josh wrote:Can anyone explain why the evaluation of If and Bool float values are rounded?
Think about each part of the statement individually as language not code - there's an underlying logic error.
Bool - make a true/false determination
Not - on the result of the true/false inversion
0.4 - of a continuous value.
In real world logic this makes no sense. Don't think of 0.4 as a discrete value - it isn't, its 0.40000000000000000000000......
However the compiler has a set of optimisation rules that it follows, and one of these is an implicit cast which says 'if you are put in a situation where a continuous variable is supplied as the operand of a function expecting discrete values - round it according to these rules'.
What the rule doesn't say is 'unless boolean functions are involved somewhere else'.
So the resulting program:
makes a true/false determination
on the result of the logical inversion
of a continuous value rounded according to the rules.
In C++ compilers you'd probably get an error or a warning about not using an explicit cast. This is one of those situations where the 'GIGO' rule applies.