This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
manual:Calculations [2017/09/06 01:29] peternlewis [Operators] |
manual:Calculations [2018/05/16 23:14] JMichaelTX Update Operators Table. Needs Fixes. |
||
---|---|---|---|
Line 23: | Line 23: | ||
Operators based on precedence from lowest to highest are: | Operators based on precedence from lowest to highest are: | ||
- | | array separator (,) | separates elements of an array | | + | | Array Separator (`,`)\\ FIXME -- this is NOT an //operator// IMO. | Allows a text Variable, which has comma separated values, to work somewhat like an Array.\\ Assume `MyKMVariable` contains "value1,value2,value3".\\ Then `MyKMVariable[2]` returns "value2". | |
- | | ternary operator (?) | a=b ? 3 : 4 | | + | | Ternary Operator (`?`) | a=b ? 3 : 4 | |
- | | bitwise or (%%|%%), bitwise and (%%&%%) and bitwise xor | operators | | + | | Bitwise OR (`|`), Bitwise AND (`&`) and Bitwise XOR | operators | |
- | | comparison operators (<, ≤, =, >, ≥, ≠) | compare for (in)equality and return 0 or 1 | | + | | Comparison Operators (`<, ≤, =, >, ≥, ≠`) | compare for (in)equality and return 0 or 1 | |
- | | shift operators (≪, ≫) | shift a number left or right | | + | | Shift Operators (`≪, ≫`) | shift a number left or right | |
- | | addition operators (+, -) | add or subtract | | + | | Arithmetic Operators\\ • Add (`+`)\\ • Subtract (`-`)\\ • Multiply (`*`)\\ • Divide (`/`) | A mathematical function that takes two operands and performs a calculation on them. | |
- | | multiplication operators (*, /, MOD) | multiply, divide or [Modulo](https://en.wikipedia.org/wiki/Modulo_operation) | | + | | [Modulo](https://en.wikipedia.org/wiki/Modulo_operation) (`i MOD n`) | The remainder of the division of i by n.\\ Both values (`i, n`) must be integer in Keyboard Maestro. | |
- | | power operator (%%^%%) | exponentiation | | + | | Power Operator (`^`) | exponentiation | |
- | | unary prefix operators (√ (Option-V), -, brackets) | square root, negation, sub-expressions | | + | | Unary Prefix Operators (`√`, `-`, `( )` ) | square root, negation, sub-expressions | |
- | | functions | a large variety of functions | | + | | functions\\ FIXME -- While technically Functions are operators, it confusing to most users to list here since everywhere else in KM they are separated. | a large variety of functions | |
- | | numbers and variables or array accesses (5,$5A,0x50,8#007,Variable,Variable[5]) | identifiers and values | | + | | Numbers and Variables or Array Accesses (5,$5A,0x50,8#007,Variable,Variable[5])\\ FIXME -- this is clear as mud. | identifiers and values | |
- | | unary postfix operators (!,%,° (Option-Shift-8)) | factorial, percent, degrees | | + | | Unary Postfix Operators (`!,%,°`)) | factorial, percent, degrees | |
You can use either `=` or `==` (v8+) for testing for equality. | You can use either `=` or `==` (v8+) for testing for equality. | ||
Line 62: | Line 62: | ||
* myWindow.y | * myWindow.y | ||
* myWindow.Top | * myWindow.Top | ||
+ | |||
+ | ===== Variable Array Access ===== | ||
+ | |||
+ | If a variable contains a sequence of numbers separated by comma (,) then you can access that variable using array notation (eg `MyVar[5]`). So if variable MyVar has a text value of `10,20,30,40,50,60`, MyVar[5] will return 50. | ||
+ | |||
+ | The index is itself an expression, so it can be arbitrarily complex. | ||
+ | |||
+ | Indices are 1-based, so MyVar[1] is the first element. If the index is 0, the size of the array is returned (so MyVar[0] would be `6`). If the index is less than zero, the array is indexed from the end (so MyVar[-5] would be `20`). | ||
===== Variable Dot Notation ===== | ===== Variable Dot Notation ===== | ||
Line 80: | Line 88: | ||
The Variable Name and Dot reference are case insensitive. | The Variable Name and Dot reference are case insensitive. | ||
- | |||
===== Text Fields ===== | ===== Text Fields ===== | ||
Line 111: | Line 118: | ||
SCREEN(Internal,Left,10%) | SCREEN(Internal,Left,10%) | ||
</code> | </code> | ||
+ | |||
+ | --- | ||
+ | |||
+ | **KeyWords:** MOD, Modulo |