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 [2019/06/17 23:45] peternlewis [Overview] |
manual:Calculations [2021/10/04 02:58] peternlewis |
||
---|---|---|---|
Line 23: | Line 23: | ||
Operators based on precedence from lowest to highest are: | Operators based on precedence from lowest to highest are: | ||
- | | Array Separator (`,`) | 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". | | + | | Array Separator (`,`) | 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 | bitwise 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. | |
- | | Arithmetic Operators\\ • Add (`+`)\\ • Subtract (`-`)\\ • Multiply (`*`)\\ • Divide (`/`) | A mathematical function that takes two operands and performs a calculation on them. | | + | | Arithmetic Multiplication Operators\\ • Multiply (`*`)\\ • Divide (`/`) | Basic mathematical operations. | |
- | | [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 an integer in Keyboard Maestro. | | + | | Arithmetic Additiona Operators\\ • Add (`+`)\\ • Subtract (`-`) | Basic mathematical operations. | |
- | | Power Operator (`^`) | exponentiation | | + | | [Modulo](https://en.wikipedia.org/wiki/Modulo_operation) (`i MOD n`) | The remainder of the division of `i` by `n`.\\ Both values (`i`, `n`) will be treated as integer.\\ `n` must not be 0.\\ the sign of the result is the same as the sign of i. | |
- | | Unary Prefix Operators (`√`, `-`, `( )` ) | square root, negation, sub-expressions | | + | | Integer division (`i DIV n`) (v9.0+)| The integer quotient of the division of `i` by `n`.\\ Both values (`i`, `n`) will be treated as integer.\\ `n` must not be 0.\\ the sign of the result matches the sign of regular division. | |
- | | [[:Functions|Functions]] | a large variety of functions | | + | | Power Operator (`^`) | exponentiation. | |
- | | Numbers and Variables or Array Accesses (5,$5A,0x50,8#007,Variable,Variable[5]) | identifiers and values | | + | | Unary Prefix Operators (`√`, `-`, `( )` ) | square root, negation, sub-expressions. | |
- | | Unary Postfix Operators (`!,%,°`)) | factorial, percent, degrees | | + | | [[:Functions|Functions]] | a large variety of functions. | |
+ | | Numbers and Variables or Array Accesses (5,$5A,0x50,8#007,Variable,Variable[5]) | identifiers and values. | | ||
+ | | Unary Postfix Operators (`!,%,°`)) | factorial, percent, degrees. | | ||
Numbers are in decimal by default, but may use base 16 if they start with `$` or `0x` (eg $5A or 0x5A), or may start with a specific base followed by a `#` (eg 8#007). | Numbers are in decimal by default, but may use base 16 if they start with `$` or `0x` (eg $5A or 0x5A), or may start with a specific base followed by a `#` (eg 8#007). | ||
Line 43: | Line 45: | ||
Operators and functions must be in uppercase to minimize conflict with variables. | Operators and functions must be in uppercase to minimize conflict with variables. | ||
+ | |||
===== Functions ===== | ===== Functions ===== | ||
The available functions are listed on the [[/Functions|wiki Functions page]]. | The available functions are listed on the [[/Functions|wiki Functions page]]. | ||
- | You can insert a function by name by choosing [[Menus#Insert_Function_by_Name|Insert Function by Name]] from the [[Menus#Edit|Edit menu]]. | + | You can insert a function by name by choosing from the [[Menus#Insert_Function|Edit ➤ Insert Function menu]] or choosing the [[Menus#Insert_Function_by_Name|Edit ➤ Insert Function by Name menu]]. |
===== Variables ===== | ===== Variables ===== | ||
Line 122: | Line 125: | ||
</code> | </code> | ||
- | --- | ||
- | |||
- | **KeyWords:** MOD, Modulo |