Color blocks are not idempotent

I just discovered that the color blocks are not idempotent :anger:
grafik
It could cause confusion

https://ai2.metricrat.co.uk/scraps/android-and-html-colour-codes

Did that -65536 come out of an AI2 color operation?

Definitely
grafik

@ewpatton has already explained all of this somewhere (probably on the old forum)

This is probably the old Forum post?

Here is the logic:

The value of the color in hex is FF000000 (255 alpha, 0 rgb). This value in decimal is 4278190080. In YAIL, the values are stored as long (64-bit) or Java Bignums (if they're larger than 2^63), which can represent this large positive value. However, when the value is passed to the Android runtime, it is passed as a Java int, which is a signed 32-bit value. When FF000000 is interpreted as a 32-bit signed integer, it's value is -16777216.

So at the bit representation they are equivalent, it's all in how the bits are interpreted.

Cheers,
Evan

1 Like

If you stretch equality to include modulo 2^32, are the two values ‘equal’ ?

Jep, fixed it
grafik
So if you want to compare colors and want to make sure theyare equal, compare with the modulo block

I have published an example:

(added to Colors FAQ)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.