Skip to content

The fine print

A collection of places where intuition fails: comparisons with a tolerance, null instead of infinity and objects equal only to themselves

0.1 + 0.2 in mlog, as everywhere, gives 0.30000000000000004. But op equal almost 0.3 answers one: it is a comparison with a tolerance — two numbers count as equal if the difference is less than one millionth. A strict comparison of the same pair gives zero.

The same example shows the rest too: division by zero turned into null, null turned out to be equal to zero by equal and not equal by strictEqual, and copper is equal only to copper.

tick 0
Operation0
=
Operation1
=
Operation2
=
Operation3
=
Operation4
=
Operation5
=
Operation6
=
Operation7
=
Stop8
@counter0number
almostnullnull
withEpsilonnullnull
strictnullnull
byZeronullnull
blankIsZeronullnull
blankStrictlynullnull
copperIsCoppernullnull
copperIsLeadnullnull
Condition How it compares
equal, notEqual with a tolerance of 0.000001
strictEqual exactly, and checks the type as well
lessThan, greaterThan and the rest exactly, with no tolerance

Hence an oddity: equal can say “equal” while lessThan says “less”, and both are right.

There is no infinity and no “not a number” in mlog variables. The moment a computation gives such an answer, the variable becomes null:

op div x 5 0 # x = null
op div y 0 0 # y = null
op sqrt z -4 # z = null

That is not our invention but how a variable is built in the game: it does not store an unusable number at all and turns it into null.

Comparison The answer
equal null 0 1 — in arithmetic null counts as zero
strictEqual null 0 0 — the types differ
op add x null 5 5
print null null

Null is not zero, but it behaves like zero everywhere except in a strict comparison and in printing. The only reliable way to tell “no value” from “the value zero” is strictEqual.

Buildings, units and content are compared by identity: equal @copper @copper is one, equal @copper @lead is zero. There is no “similar”.

Two things follow from that:

  • two units of the same type are not equal. To compare types you ask sensor kind @unit @type and compare the types instead;
  • a building from getlink and the same building from radar are one and the same object, and comparing them will confirm it.

A string can be put in a variable, printed, compared for equality and read character by character through read. What you cannot do with it is add it up and compare it in order:

op add x "abc" 5 # not an addition: a string in arithmetic is a one
op lessThan y "abc" 5 # compares a one, not a string

In numeric operations a string behaves like an object: present is one, absent is zero.

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.