Certain arithmetic and bitwise operators return values contradictory to the DM reference when the first operand is null
Numbered Steps to Reproduce Problem:
Run the code below
Code Snippet to Reproduce Problem:
world/New()
var/N = null
var/K = 1
world.log << "N: [n(N)]" // *null*
world.log << "K: [n(K)]" // 1
world.log << "N*K: [n(N * K)]; expected 0" // *null*
world.log << "N/K: [n(N / K)]; expected 0" // *null*
N *= K
world.log << "N*=K: [n(N)]; expected 0" // *null*
N = null
N /= K
world.log << "N/=K: [n(N)]; expected 0" // *null*
N = null
N |= K
world.log << "N|=K: [n(N)]; expected 1" // 0
N = null
N ^= K
world.log << "N^=K: [n(N)]; expected 1" // 0
N = null
proc/n(n)
if(n == null) return "*null*"
return n
Expected Results:
For null to behave identically to 0 in all arithmetic and bitwise operations, as specified in the DM reference: "in a numeric context (like a mathematical operation), null evaluates to 0" ( http://www.byond.com/docs/ref/info.html#/DM/null )
Actual Results:
In multiplication and division, null as the first argument causes the result to also be null.
In in-place OR and XOR, null as the initial value of the var causes the final value of the var to be zero.
Does the problem occur:
Every time? Or how often? Every time.
In other games? Not relevant.
In other user accounts? Yes.
On other computers? Yes.
When does the problem NOT occur? Unknown.
Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? (Visit http://www.byond.com/download/build to download old versions for testing.) Unknown.
Workarounds: Explicitly check for null in all usages where it may be the left operand to * or /, and where it may be the value of the variable on the left of |= or ^=. Alternatively, use the form A = A | B instead of A |= B for OR and XOR where A may be null.
Still an issue in 508.1294.