Math Expression

Description

Calculate math expressions using placeholders and an array of values.

 

Properties

Triggers Immediately

Expression A math expression. E.g 1 + 3. Use %d as a placeholder for integers and %f as a placeholder for decimals. See the table below for a full list of place holders.
Values An array of values used to populate the placeholders in your expression.

 

Outputs

Result The result of evaluation the expression
Error If the expression is malformed this will contain the error message.

 

Examples

  • Compute the addition of two integers %d + %d with values [1, 5].
  • Compute the math expression 5 * 3.
  • Multiply two floating point numbers %f * %f with values [3.2, 4.7].
  • Use the value from the array behaviour for the values input.
  • Round up e^3 by doing ceiling:(exp(3))

 

Functions

Function

Description

Example Usage

add:to:

Add one value to an other

add:to(1, 2) produces 3

from:subtract:

Subtract one value from another from:subtract:(5, 2) produces 3

mutliply:by:

Multiply one value by another. 

multiply:by:(6, 3) produces 18

divide:by:

Divide one value by another.

divide:by:(10, 2) produces 5

modulus:by:

Perform a modulus operation.

modulus:by:(9, 2) produces 1

abs:

Get the absolute value. 

abs:(-1) produces 1.

sqrt:

Get the square root of a value.

sqrt:(16) produces 4.

log:

Evaluate the log_10  of a value.

log:(100) produces 2

ln:

Evaluate the natural logarithm/log_e of a value.

ln:(3) produces 1.09861228866811

raise:toPower:

Raise one value to the power of another. 

raise:toPower:(2, 5) produces 32
exp:

Evaluates e^x. 

exp:(1) = e^1 = 2.718281828459045

ceiling:

Evaluate the ceiling function (round up). 

ceiling:(1.23) produces 2

trunc:

Truncate a value (round down).

trunc:(1.23) produces 1

random

Get a random value between 0 and 1. E.g random()

random()

bitwiseAnd:with:

Perform the bitwise And operator on two values

bitwiseAnd:with:(1, 0) produces 0

bitwiseOr:with:

Perform the bitwise Or operator on two values

bitwiseOr:with:(1, 0) produces 1

bitwiseXor:with:

Perform the bitwise Xor operator on two values

bitwiseXor:with:(5, 3) produces 6

leftshift:by:

Perform a left shift operation on the first value by the second

leftshift:by:(1,5) produces 32

rightshift:by:

Perform a right shift operation on the first value by the second

rightshift:by:(2,1) produces 1

onesComplement:

Perform the ones complement (swap the ones and zeros of the binary representation of a number)

onesComplement:(5) produces 2

now

Get the current date and time

now() produces 2020-11-27 19:30:31 +0000 at the time of writing this


Placeholders (String format specifiers)

Specifier

Description

%@

Objective-C object, printed as the string returned by descriptionWithLocale: if available, or description otherwise. Also works with CFTypeRef objects, returning the result of the CFCopyDescription function.

%%

The '%' character.

%d, %D

Signed 32-bit integer (int).

%u, %U

Unsigned 32-bit integer (unsigned int).

%x

Unsigned 32-bit integer (unsigned int), printed in hexadecimal using the digits 0–9 and lowercase a–f.

%X

Unsigned 32-bit integer (unsigned int), printed in hexadecimal using the digits 0–9 and uppercase A–F.

%o, %O

Unsigned 32-bit integer (unsigned int), printed in octal.

%f

64-bit floating-point number (double).

%e

64-bit floating-point number (double), printed in scientific notation using a lowercase e to introduce the exponent.

%E

64-bit floating-point number (double), printed in scientific notation using an uppercase E to introduce the exponent.

%g

64-bit floating-point number (double), printed in the style of %e if the exponent is less than –4 or greater than or equal to the precision, in the style of %f otherwise.

%G

64-bit floating-point number (double), printed in the style of %E if the exponent is less than –4 or greater than or equal to the precision, in the style of %f otherwise.

%c

8-bit unsigned character (unsigned char).

%C

16-bit UTF-16 code unit (unichar).

%s

Null-terminated array of 8-bit unsigned characters. Because the %s specifier causes the characters to be interpreted in the system default encoding, the results can be variable, especially with right-to-left languages. For example, with RTL, %s inserts direction markers when the characters are not strongly directional. For this reason, it’s best to avoid %s and specify encodings explicitly.

%S

Null-terminated array of 16-bit UTF-16 code units.

%p

Void pointer (void *), printed in hexadecimal with the digits 0–9 and lowercase a–f, with a leading 0x.

%a

64-bit floating-point number (double), printed in scientific notation with a leading 0x and one hexadecimal digit before the decimal point using a lowercase p to introduce the exponent.

%A

64-bit floating-point number (double), printed in scientific notation with a leading 0X and one hexadecimal digit before the decimal point using a uppercase P to introduce the exponent.

%F

64-bit floating-point number (double), printed in decimal notation.

 

math.gif

0 Comments

Article is closed for comments.