Arithmetic functions perform basic calculations and mathematical calculations on the field values of a log. This topic lists the available functions and mathematical constants by type, and describes the syntax, parameters, return value, and examples of each function.
Usage notes
The following conventions apply to all arithmetic functions in this topic:
Function families — Functions whose names begin with
op_perform basic calculations. Functions whose names begin withmat_perform mathematical calculations.MATH_PIandMATCH_Eare mathematical constants that you pass to a function as a value.Overlapping operations — Some operations are available in both function families. For example, both
op_absandmat_fabscalculate an absolute value. Compare the example in each section to see the result that each function returns.Input types — The parameter table in each section lists the types that a parameter accepts. Most parameters accept a number or a numeric string. The
value1parameter ofop_mulalso accepts a string, a tuple, or a list.Angle units —
mat_sin,mat_cos, andmat_tanaccept the input value in radians, andmat_acos,mat_asin, andmat_atanreturn the result in radians. To convert degrees to radians, usemat_radians. To convert radians to degrees, usemat_degrees.Examples — Each example shows the raw log, the transformation rule that is applied to the log, and the result of the transformation.
To use a negative value, use the op_neg(positive value) function. For example, to represent -1, use op_neg(1).
Function list
The following table lists the arithmetic functions and mathematical constants by type.
Type | Function | Description |
Basic calculations | op_sum | Calculates the sum of the input values. |
op_abs | Calculates the absolute value of an input value. | |
op_div_floor | Performs integer division on the input values. | |
op_div_true | Performs division on the input values. | |
op_pow | Raises a value to a specified power. | |
op_mul | Multiplies the input values. | |
op_neg | Reverses the sign of an input value. | |
op_mod | Performs a modulo operation on the input values. | |
op_sub | Subtracts one input value from another. | |
op_round | Rounds an input value. | |
Mathematical calculations | mat_ceil | Rounds an input value up to the nearest integer. |
mat_exp | Calculates an exponential function with base e. | |
mat_fabs | Calculates the absolute value of an input value. | |
mat_floor | Rounds an input value down to the nearest integer. | |
mat_log | Calculates the logarithm of an input value. | |
mat_log10 | Calculates the base-10 logarithm of an input value. | |
mat_sqrt | Calculates the square root of an input value. | |
mat_degrees | Converts radians to degrees. | |
mat_radians | Converts degrees to radians. | |
mat_sin | Calculates the sine of an input value in radians. | |
mat_cos | Calculates the cosine of an input value in radians. | |
mat_tan | Calculates the tangent of an input value in radians. | |
mat_acos | Calculates the arccosine of an input value. The result is in radians. | |
mat_asin | Calculates the arcsine of an input value. The result is in radians. | |
mat_atan | Calculates the arctangent of an input value. The result is in radians. | |
mat_atan2 | Calculates the arctangent of the specified coordinates. | |
mat_atanh | Calculates the inverse hyperbolic tangent of an input value. | |
mat_hypot | Calculates the Euclidean norm of the input values. | |
Mathematical constants | MATH_PI | The mathematical constant pi. |
MATCH_E | The mathematical constant e. |
op_sum
Calculates the sum of the input values.
Syntax
op_sum(value1, value2, ...)Parameters
Parameter name | Parameter type | Required | Description |
value1 | Number or string (numeric) | Yes | The value to be calculated. |
value2 | Number or string (numeric) | Yes | The value to be calculated. |
Response
The sum of the input values.
Examples
Calculate the total price from the course_price and goods_price fields.
Raw log
course_price: 12
goods_price: 2Transformation rule
e_set("total_price", op_sum(v("course_price"), v("goods_price")))Result
course_price: 12
goods_price: 2
total_price: 14op_abs
Calculates the absolute value of an input value.
Syntax
op_abs(value)Parameters
Parameter name | Parameter type | Required | Description |
value | Number or string (numeric) | Yes | The value to be calculated. |
Response
The absolute value of the input value.
Examples
Calculate the absolute value of the course_price field.
Raw log
course_price: -4Transformation rule
e_set("op_abs", op_abs(v("course_price")))Result
course_price: -4
op_abs: 4op_div_floor
Performs integer division on the input values.
Syntax
op_div_floor(value1, value2)Parameters
Parameter name | Parameter type | Required | Description |
value1 | Number or string (numeric) | Yes | The value to be calculated. |
value2 | Number or string (numeric) | Yes | The value to be calculated. |
Response
The integer part of the quotient of value1 divided by value2.
Examples
Calculate the unit price based on the course_price and count fields.
Raw log
course_price: 4
count: 2Transformation rule
e_set("op_div_floor", op_div_floor(v("course_price"), v("count")))Result
course_price: 4
count: 2
op_div_floor: 2op_div_true
Performs division on the input values.
This function automatically converts data types. You can pass in string or integer data.
Syntax
op_div_true(value1, value2)Parameters
Parameter name | Parameter type | Required | Description |
value1 | Number or string (numeric) | Yes | The value to be calculated. |
value2 | Number or string (numeric) | Yes | The value to be calculated. |
Response
The quotient of value1 divided by value2.
Examples
- Example 1: Calculate the unit price based on the fruit_price and count fields.
Raw log
fruit_price: 9
count: 2Transformation rule
e_set("op_div_true", op_div_true(v("fruit_price"), v("count")))Result
fruit_price: 9
count: 2
op_div_true: 4.5Example 2: Calculate the acceleration and round the result. The formula is
a = (one_speed-two_speed)/time.Raw log
one_speed: 9
two_speed: 2
time: 3Transformation rule
e_set("a", op_round(op_div_true(op_sub(v("one_speed"), v("two_speed")), v("time")), 2))Result
one_speed: 9
two_speed: 2
time: 3
a: 2.33op_pow
Raises a value to a specified power.
Syntax
op_pow(value1, value2)Parameters
Parameter name | Parameter type | Required | Description |
value1 | Number or string (numeric) | Yes | The value to be calculated. |
value2 | Number or string (numeric) | Yes | The value to be calculated. |
Response
The value of value1 raised to the power of value2.
Examples
Calculate the value of course raised to the power of pow.
Raw log
course: 100
pow: 2Transformation rule
e_set("pow_course", op_pow(v("course"), v("pow")))Result
course: 100
pow: 2
pow_course: 10000op_mul
Multiplies the input values.
Syntax
op_mul(value1, value2)Parameters
Parameter name | Parameter type | Required | Description |
value1 | Number, string, tuple, list, and so on | Yes | The value to be calculated. |
value2 | Number | Yes | The value to be calculated. |
Response
- If value1 and value2 are numbers, the function returns the product of the two values.
If value1 is a string, a tuple, or a list, the function returns a value of the same type that is repeated value2 times.
Examples
- Example 1: Calculate the total price based on the course and price fields.
Raw log
course: 10
price: 23Transformation rule
e_set("total_price", op_mul(ct_int(v("course")), ct_int(v("price"))))Result
course: 10
price: 23
total_price: 230Example 2: Multiply the value of the course field by 3.
Raw log
course: "abc"Transformation rule
e_set("course", op_mul(v("course"), 3))Result
course: "abcabcabc"op_neg
Reverses the sign of an input value.
Syntax
op_neg(value)Parameters
Parameter name | Parameter type | Required | Description |
value | Number or string (numeric) | Yes | The value to be calculated. |
Response
The input value with its sign reversed.
Examples
- Raw log
course: -100Transformation rule
e_set("account", op_neg(v("course")))Result
course: -100
account: 100op_mod
Performs a modulo operation on the input values.
Syntax
op_mod(value1, value2)Parameters
Parameter name | Parameter type | Required | Description |
value1 | Number or string (numeric) | Yes | The value to be calculated. |
value2 | Number or string (numeric) | Yes | The value to be calculated. |
Response
The remainder of value1 divided by value2.
Examples
- Raw log
course: 4
count: 3Transformation rule
e_set("op_mod", op_mod(v("course"), v("count")))Result
course: 4
count: 3
op_mod: 1op_sub
Subtracts one input value from another.
Syntax
op_sub(value1, value2)Parameters
Parameter name | Parameter type | Required | Description |
value1 | Number or string (numeric) | Yes | The value to be calculated. |
value2 | Number or string (numeric) | Yes | The value to be calculated. |
Response
The result of value1 minus value2.
Examples
Calculate the result of subtracting the count_apple value from the count value.
Raw log
count: 6
count_apple: 3Transformation rule
e_set("sub_number", op_sub(v("count"),v("count_apple")))Result
count: 6
count_apple: 3
sub_number: 3op_round
Rounds an input value.
Syntax
op_round(value, number)Parameters
Parameter name | Parameter type | Required | Description |
value | Number or string (numeric) | Yes | The value to be calculated. |
number | Number | Yes | The number of decimal places to keep after rounding. The default value is 0. |
Response
The rounded value.
Examples
Round the value of the price field to one decimal place.
Raw log
price: 4.56Transformation rule
e_set("round_price", op_round(v("price"),1))Result
price: 4.56
round_price: 4.6mat_ceil
Rounds an input value up to the nearest integer.
Syntax
mat_ceil(value)Parameters
Parameter name | Parameter type | Required | Description |
value | Number or string (numeric) | Yes | The value to be calculated. |
Response
The smallest integer that is greater than or equal to the specified value.
Examples
- Raw log
price: 4.1Transformation rule
e_set("mat_ceil", mat_ceil(v("price")))Result
price: 4.1
mat_ceil: 5mat_exp
Calculates an exponential function with base e.
Syntax
mat_exp(value)Parameters
Parameter name | Parameter type | Required | Description |
value | Number or string (numeric) | Yes | The value to be calculated. |
Response
e raised to the power of the input value.
Examples
- Raw log
number: 2Transformation rule
e_set("e_x", mat_exp(v("number")))Result
number: 2
e_x: 7.38905609893065mat_fabs
Calculates the absolute value of an input value.
Syntax
mat_fabs(value)Parameters
Parameter name | Parameter type | Required | Description |
value | Number or string (numeric) | Yes | The value to be calculated. |
Response
The absolute value of the input value.
Examples
- Raw log
course_price: -10Transformation rule
e_set("mat_fabs", mat_fabs(v("course_price")))Result
course_price: -10
mat_fabs: 10.0mat_floor
Rounds an input value down to the nearest integer.
Syntax
mat_floor(value)Parameters
Parameter name | Parameter type | Required | Description |
value | Number or string (numeric) | Yes | The value to be calculated. |
Response
The largest integer that is less than or equal to the specified value.
Examples
- Raw log
course_price: 4.9Transformation rule
e_set("mat_floor", mat_floor(v("course_price")))Result
course_price: 4.9
mat_floor: 4mat_log
Calculates the logarithm of an input value.
Syntax
mat_log(value1,value2)Parameters
Parameter name | Parameter type | Required | Description |
value1 | Number or string (numeric) | Yes | The value to be calculated. |
value2 | Number or string (numeric) | Yes | The value to be calculated. |
Response
The logarithm of the input value.
Examples
- Raw log
number1: 100
number2: 10Transformation rule
e_set("mat_log", mat_log(v("number1"),v("number2")))Result
number1: 100
number2: 10
mat_log: 2.0mat_log10
Calculates the base-10 logarithm of an input value.
Syntax
mat_log10(value)Parameters
Parameter name | Parameter type | Required | Description |
value | Number or string (numeric) | Yes | The value to be calculated. |
Response
The base-10 logarithm of the input value.
Examples
- Raw log
number: 100Transformation rule
e_set("number2", mat_log10(v("number")))Result
number: 100
number2: 2.0mat_sqrt
Calculates the square root of an input value.
Syntax
mat_sqrt(value)Parameters
Parameter name | Parameter type | Required | Description |
value | Number or string (numeric) | Yes | The value to be calculated. |
Response
The square root of the input value.
Examples
- Raw log
number1: 100Transformation rule
e_set("sqrt_account", mat_sqrt(v("number1")))Result
number1: 100
sqrt_account: 10.0mat_degrees
Converts radians to degrees.
Syntax
mat_degrees(value)Parameters
Parameter name | Parameter type | Required | Description |
value | Number or string (numeric) | Yes | The value to be calculated. |
Response
The result in degrees.
Examples
- Raw log
num: 1Transformation rule
e_set("mat_degrees", mat_degrees(v("num")))Result
num: 1
mat_degrees: 57.29577951308232mat_radians
Converts degrees to radians.
Syntax
mat_radians(value)Parameters
Parameter name | Parameter type | Required | Description |
value | Number or string (numeric) | Yes | The value to be calculated. |
Response
The result in radians.
Examples
- Raw log
rad: 30Transformation rule
e_set("mat_radians", mat_radians(v("rad")))Result
rad: 30
mat_radians: 0.5235987755982988mat_sin
Calculates the sine of an input value in radians.
Syntax
mat_sin(value)Parameters
Parameter name | Parameter type | Required | Description |
value | Number or string (numeric) | Yes | The value to be calculated. |
Response
The sine of the input value.
Examples
- Raw log
sin: 90Transformation rule
e_set("mat_sin", mat_sin(v("sin")))Result
sin: 90
mat_sin: 0.8939966636005579mat_cos
Calculates the cosine of an input value in radians.
Syntax
mat_cos(value)Parameters
Parameter name | Parameter type | Required | Description |
value | Number or string (numeric) | Yes | The value to be calculated. |
Response
The cosine of the input value.
Examples
- Raw log
cos: 30Transformation rule
e_set("mat_cos", mat_cos(v("cos")))Result
cos: 30
mat_cos: 0.15425144988758405mat_tan
Calculates the tangent of an input value in radians.
Syntax
mat_tan(value)Parameters
Parameter name | Parameter type | Required | Description |
value | Number or string (numeric) | Yes | The value to be calculated. |
Response
The tangent of the input value.
Examples
- Raw log
tan: 30Transformation rule
e_set("mat_tan", mat_tan(v("tan")))Result
tan: 30
mat_tan: 1.6197751905438615mat_acos
Calculates the arccosine of an input value. The result is in radians.
Syntax
mat_acos(value)Parameters
Parameter name | Parameter type | Required | Description |
value | Number or string (numeric) | Yes | The value to be calculated. |
Response
The arccosine of the input value, in radians.
Examples
- Raw log
acos: 1Transformation rule
e_set("mat_acos", mat_acos(v("acos")))Result
acos: 1
mat_acos: 0.0mat_asin
Calculates the arcsine of an input value. The result is in radians.
Syntax
mat_asin(value)Parameters
Parameter name | Parameter type | Required | Description |
value | Number or string (numeric) | Yes | The value to be calculated. |
Response
The arcsine of the input value, in radians.
Examples
- Raw log
asin: 1Transformation rule
e_set("mat_asin", mat_asin(v("asin")))Result
asin: 1
mat_asin: 1.5707963267948966mat_atan
Calculates the arctangent of an input value. The result is in radians.
Syntax
mat_atan(value)Parameters
Parameter name | Parameter type | Required | Description |
value | Number or string (numeric) | Yes | The value to be calculated. |
Response
The arctangent of the input value, in radians.
Examples
- Raw log
atan: 1Transformation rule
e_set("mat_atan", mat_atan(v("atan")))Result
atan: 1
mat_atan: 0.7853981633974483mat_atan2
Calculates the arctangent of the specified coordinates.
Syntax
mat_atan2(x,y)Parameters
Parameter name | Parameter type | Required | Description |
x | Number or string (numeric) | Yes | The x-coordinate. |
y | Number or string (numeric) | Yes | The y-coordinate. |
Response
The arctangent of the specified coordinates.
Examples
- Raw log
atan1: 1
atan2: 2Transformation rule
e_set("mat_atan2", mat_atan2(v("atan1"),v("atan2")))Result
atan1: 1
atan2: 2
mat_atan2: 0.4636476090008061mat_atanh
Calculates the inverse hyperbolic tangent of an input value.
Syntax
mat_atanh(value)Parameters
Parameter name | Parameter type | Required | Description |
value | Number or string (numeric) | Yes | The value to be calculated. |
Response
The inverse hyperbolic tangent of the input value.
Examples
- Raw log
atanh: 0.5Transformation rule
e_set("mat_atanh", mat_atanh(v("atanh")))Result
atanh: 0.5
mat_atanh: 0.5493061443340548mat_hypot
Calculates the Euclidean norm of the input values.
Syntax
mat_hypot(value1,value2)Parameters
Parameter name | Parameter type | Required | Description |
value1 | Number or string (numeric) | Yes | The x-coordinate. |
value2 | Number or string (numeric) | Yes | The y-coordinate. |
Response
The Euclidean norm of the input values.
Examples
- Raw log
hypot1: 1
hypot2: 2Transformation rule
e_set("mat_hypot", mat_hypot(v("hypot1"),v("hypot2")))Result
hypot1: 1
hypot2: 2
mat_hypot: 2.23606797749979MATH_PI
The mathematical constant pi.
Raw log
a: 2Transformation rule
e_set("result", op_sum(v("a"), MATH_PI))Result
a: 2
result: 5.141592653589793MATCH_E
The mathematical constant e.
Raw log
a: 2Transformation rule
e_set("result", op_sum(v("a"), MATCH_E))Result
a: 2
result: 4.718281828459045