[SOLVED] Unexpected results with Val math operators

Unfortunately, all of these conventions are universal across pretty much all C like programming languages. So it may seem weird but it is a standard.

Some rules for the logic behind them which might help you make sense of things:

  • A single = always means assignement. So TestA = TestB means Assign the value of TestB to TestA. You should pretty much never see a single = in an if statement.

  • All of the equals comparisons will have at least two characters. So to test for equality you would use ==. Any modifiers to the equals (<, >, !) will always go first. So you have not equals !=, less than equals <=, greater than equal >= and never =!, =>, or =<. NOTE, in some lanuages those may represent other operators.

  • There is one special case which is specific to the Rules DSL where if you have null as one of the operands, you must use three equal signs ===. <skip to the next buttlen unless you want to learn the details why> In the Rules DSL when you call TestA == TestB behind the scenes it is calling TestA.equals(TestB). However, when null is one of the operands, because null isn’t an Object, there is no .equals method to call. Therefore you need to call === which is the identity operator. This operator means “are the two operands pointing to the same place in memory” meaning not only are the two equivilent, they are the same Object.

  • All the other boolean comparison operators are one character: <, >, !.

  • Not ! is a little weird in that if it is not used with = then it goes before the comparison you are trying to negate. if(!(TestA < TestB)). ! is more useful when you have a boolean saved to a variable !myBoolean.

Again, I’ll emphasize that none of the above is specific to Java or the Rules DSL. The operators work like this almost universally across most programming languges to some degree or other with the most variation being the not operator.