Mixed-type rules
There's no general implicit conversion. Each operator has a short list of kind combinations it
understands. Any other combination doesn't raise an error. It quietly gives Integer 0 (or
false for an ordering) and the script keeps running. That's deliberate, so one odd value doesn't
abort an action halfway through. It also means a mistyped expression fails silently, so check with
UtilityPrint when a result looks wrong.
| Operator | Accepted combinations → result | Anything else |
|---|---|---|
+ | Text + Text → Text (concatenation) Integer + Integer → Integer Integer/Real mix → Real | 0 |
- * | Integer ∘ Integer → Integer Integer/Real mix → Real | 0 |
/ | Integer / Integer → Integer, truncated toward zero (-7 / 2 is -3)Integer/Real mix → Real dividing by zero → 0 or 0.0, no error | 0 |
== != | same kind → compared by value (Text exactly and case-sensitively, Window by handle) Integer vs Real → compared numerically ( 5 == 5.0) | never equal: 1 == true, "5" == 5 and w == 0 are all false |
< <= > >= | two numbers (Integer/Real mix allowed) → numeric order Text vs Text → ordinal, case-sensitive (UTF-16 code units: "Z" < "a") | false for all four, so !(a < b) doesn't mean a >= b here |
&& || ! | any kinds, via truthiness → Bool | |
& | ^ | Integer ∘ Integer → Integer | 0 (a Bool or Real operand counts: true & true is 0) |
<< >> | Integer by Integer 0–63 → Integer. >> keeps the sign: -16 >> 2 is -4. | 0, including shift amounts below 0 or above 63 |
unary - | Integer → Integer, Real → Real | 0 |
~ | Integer → Integer (~0 is -1) | 0 |
Converting between kinds:
| From → To | How |
|---|---|
| Integer → Real | automatic when passed to a builtin parameter declared Real; elsewhere n * 1.0 (any arithmetic with a Real gives a Real) |
| Real → Integer | MathRound(r) (halves away from zero), MathFloor(r) or MathCeil(r) |
| anything → Text | StringFormat("{0}", value, "") |
| Bool → Integer | if (b) n = 1; else n = 0; |
| Text → number | StringToNumber(text, false) for what a person typed (their regional format; digit groups must follow it, so 1,5 isn't a number for an English (United States) user), true for machine text (. decimal point, no grouping). Integer when whole, else Real; StringIsNumber first if the text might not be a number (see this example). |
| number → Text | StringFromNumber(n, decimals, invariantCulture), decimals -1 for as many as needed |
| Integer → hex Text | no builtin does this. Build it with shifts (see this example). |