This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| crpl:docs:eq [2013/01/18 06:05] – grauniad | crpl:docs:eq [2025/02/14 14:57] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ~~DISCUSSION~~ | + | |
| <- [[crpl: | <- [[crpl: | ||
| ===== eq ===== | ===== eq ===== | ||
| Line 10: | Line 10: | ||
| Top two items are popped from the stack and ' | Top two items are popped from the stack and ' | ||
| comparison is performed. 0 or 1 is pushed back to the stack where 1 indicates true. | comparison is performed. 0 or 1 is pushed back to the stack where 1 indicates true. | ||
| + | |||
| + | === Comparing unlike types === | ||
| + | When trying to do a comparison where one argument is a string and the other is an int, the string gets coerced into an int. If the string is something like " | ||
| + | |||
| + | In particular, if x may be a string or number, (<-x " | ||
| + | |||
| + | The ' | ||
| + | - If either argument is a floating point number, then treat both arguments as floating point numbers, coercing the other argument if necessary. | ||
| + | - If both arguments are strings, then do string comparisons. | ||
| + | - If neither 1 nor 2 above is true, then treat each argument as an int, coercing the arguments if necessary. | ||
| + | |||
| === Examples === | === Examples === | ||
| < | < | ||
| Line 17: | Line 28: | ||
| 45 50 gt # False, 45 is not greater than 50 | 45 50 gt # False, 45 is not greater than 50 | ||
| 50 50 gt # False, 50 is not greater than 50</ | 50 50 gt # False, 50 is not greater than 50</ | ||
| + | |||
| + | Examples of comparing with unlike types | ||
| + | < | ||
| + | " | ||
| + | 0 ->zero | ||
| + | 1 ->one | ||
| + | Trace(< | ||
| + | Trace(< | ||
| + | |||
| + | " | ||
| + | Trace(< | ||
| + | Trace(< | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | # If core doesn' | ||
| + | # Then " | ||
| + | Trace(GetScriptVar(< | ||
| + | # The following version returns TRUE only if core has Script.crpl attached with | ||
| + | # a variable " | ||
| + | Trace(GetScriptVar(< | ||
| + | </ | ||