Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Math

HEMTT includes a built-in mathematical expression evaluator used in config files. This allows you to use arithmetic operations, trigonometric functions, and angle conversions directly in config values, reducing the need for manual calculations or __EVAL.

The evaluator is automatically applied when parsing config files, allowing expressions like value = 1 + 2; to be evaluated to value = 3;.

Supported Operators

Arithmetic Operators

OperatorDescriptionExample
+Addition2 + 35
-Subtraction5 - 23
*Multiplication2 * 36
/Division6 / 23
^Exponentiation2 ^ 38
%Modulo5 % 21

Operator Precedence

Operations follow standard mathematical precedence:

  1. Unary minus (negation): -x
  2. Exponentiation: ^
  3. Multiplication, Division, Modulo: *, /, %
  4. Addition, Subtraction: +, -

Parentheses can be used to override precedence:

1 + 2 * 3        → 7
(1 + 2) * 3      → 9

Functions

Trigonometric Functions

All trigonometric functions work with radians.

FunctionDescriptionExample
sin(x)Sinesin(0)0
cos(x)Cosinecos(0)1
tan(x) or tg(x)Tangenttan(0)0
asin(x)Arcsineasin(1)1.5708... (π/2)
acos(x)Arccosineacos(1)0
atan(x) or atg(x)Arctangentatan(0)0

Angle Conversion Functions

FunctionDescriptionExample
rad(x)Convert degrees to radiansrad(180)3.14159... (π)
deg(x)Convert radians to degreesdeg(pi)180

Constants

ConstantValue
pi3.14159265…

Examples

Basic Calculations

1 + 1                    → 2
10 - 3                   → 7
4 * 5                    → 20
20 / 4                   → 5
2 ^ 10                   → 1024
17 % 5                   → 2

With Parentheses

(1 + 2) * 3              → 9
1 + (2 * 3)              → 7
((2 + 3) * 4) - 1        → 19

Negative Numbers

-5                       → -5
1 + -2                   → -1
1 - -2                   → 3
2 * -(3 + 1)             → -8

Trigonometric

sin(0)                   → 0
cos(0)                   → 1
sin(pi / 2)              → 1
cos(pi)                  → -1
tan(0)                   → 0

Angle Conversion

rad(90)                  → 1.5708... (π/2)
rad(180)                 → 3.14159... (π)
deg(pi)                  → 180
deg(pi / 2)              → 90

Complex Expressions

2 * sin(pi / 6)          → 1 (sin(30°) = 0.5)
deg(atan(1))             → 45
cos(rad(60)) + sin(rad(30))  → 1
(pi * 2) ^ 2             → 39.478...

With Constants

pi                       → 3.14159...
2 * pi                   → 6.28318... (circumference factor)
pi * 5 ^ 2               → 78.539... (area of circle with radius 5)

Arma Config Examples

Since this evaluator is used in Arma 3 config files, here are practical examples of how to use math expressions in your configurations:

Basic Config Values

class MyClass {
    // Simple arithmetic
    cost = 100 + 50;                     // Evaluates to 150
    multiplier = 2 * 3.5;                // Evaluates to 7
    
    // Damage calculations
    maxDamage = 100 / 2;                 // Evaluates to 50
    armorCoefficient = 1 / 0.8;          // Evaluates to 1.25
};

Using Constants and Functions

class MyWeapon {
    // Angles and rotations
    rotationAngle = rad(45);             // Convert 45° to radians
    deploymentAngle = deg(pi / 4);       // Convert π/4 radians to degrees
    
    // Trigonometric calculations
    offsetX = cos(rad(45)) * 2;
    offsetY = sin(rad(30)) * 5;
};

Invalid expressions will return an error:

1 +                      → Error (incomplete expression)
(1 + 1                   → Error (mismatched parentheses)
1 & 1                    → Error (invalid operator)