Skip to content

Comparisons and logic

A comparison is a number too, and it can be worked with like one

easyYou need: op: arithmetic

A comparison in mlog is not a special construct but an op operation like addition. Its answer is a number too: 1 if true and 0 if not. It can be put into a variable, added to another, passed on — it is no different from an ordinary number.

tick 0
Set0
=
Set1
=
Operation2
=
Operation3
=
Operation4
=
Operation5
=
@counter0number
coppernullnull
limitnullnull
lownullnull
plentynullnull
bothnullnull
atLeastOnenullnull

There is 40 copper and the limit is 100. The first comparison answers with a one, the second with a zero.

Operation In the block True when
equal == the numbers are equal (with a tolerance of 0.000001)
notEqual not they are not equal
lessThan < the first is less than the second
lessThanEq <= less than or equal
greaterThan > greater
greaterThanEq >= greater than or equal

The second column is what is written on the button in the block. It does not always match: “not equal” is labelled not, with no equals sign at all, and a confusion of its own comes with that — see below.

About equal’s tolerance and how strictEqual differs from it, see the lesson «Whole numbers and precision».

land is “and”: a one only if both numbers are non-zero. In the example both came out zero, because the second condition did not hold.

There is, however, no separate “or” operation in mlog. or is used instead — it is bitwise, but on ones and zeroes it behaves exactly like “or”, because 1 or 0 in bits is just 1 or 0. In the example atLeastOne came out a one.

The group’s most common trap, and it starts with the labels. The operation list has not — a bitwise inversion — but on the button it is labelled flip. And the label not goes to a completely different operation: that is how “not equal”, notEqual, is written.

In the reference On the button What it is
notEqual not not equal
not flip bitwise inversion

Now for the second row: op not is a bitwise inversion, not a logical “not”:

tick 0
Operation0
=
Operation1
=
@counter0number
bitwisenullnull
logicalnullnull

not 1 gives −2, not 0. What happens to the bits is in the lesson «Bitwise operations»; what matters here is something else: the operation is no good for negation.

A logical “not” is written as a comparison with zero: op equal answer condition 0. If the condition was a one it becomes zero; if it was zero it becomes one.

Branching in mlog is done not by op but by jump, whose condition is written right into the jump block. A comparison through op is for when the answer has to be kept rather than checked once: to add up several conditions and see how many held, to hand a number to print, to put it into memory, to give it back to another processor.

Unofficial fan project, not affiliated with Anuke. Mindustry sprites, fonts and translations © Anuke, used under GPL-3.0; Fira Code under OFL-1.1. Site code is GPL-3.0.