User Tools

Site Tools


manual:Calculations

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
manual:Calculations [2018/05/16 22:07]
JMichaelTX
manual:Calculations [2018/06/30 03:24]
peternlewis [Operators]
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 ​(`,`) | 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 an 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](https://​wiki.keyboardmaestro.com/​Functions) ​| 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]) | identifiers and values | 
-unary postfix operators ​(!,​%,​° ​(Option-Shift-8)) | factorial, percent, degrees |+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). 
 + 
 +[Variables](https://​wiki.keyboardmaestro.com/​manual/​Variables) can be used if they contain numeric expressions,​ including an *array* of numbers separated by commas, in which case you can use an array index to select the desired number. ​
  
 You can use either `=` or `==` (v8+) for testing for equality. You can use either `=` or `==` (v8+) for testing for equality.
  
 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 =====
  
Line 48: Line 51:
 ===== Variables ===== ===== Variables =====
  
-Variables ​are used unadorned ​in numeric calculations.  Do not try to use tokens (like <del>%Variable%MyVar%</​del>​) in numeric calculation fields, just use MyVar by itself. The variable must contain a valid numeric value, or an expression (v8+) that evaluates to a valid numeric value. ​ So for example, if MyVar contains a text value of `2*3`, then the calculation `4*MyVar` will return 24.+In numeric calculation fields, Variable Names are used without the `%` that are used in text token fields.  Do not try to use tokens (like `%Variable%MyVar%`) in numeric calculation fields, just use MyVar by itself. The variable must contain a valid numeric value, or an expression (v8+) that evaluates to a valid numeric value. ​ So for example, if MyVar contains a text value of `2*3`, then the calculation `4*MyVar` will return 24.
  
 ===== Screen Coordinates ===== ===== Screen Coordinates =====
manual/Calculations.txt · Last modified: 2023/10/02 00:38 by peternlewis