Formula Reference

Formulas are written in the portal's Formulas tab and delivered encrypted to your aircraft after activation (L3DRM 3.0 or newer). Your aircraft calls them with DRM_EVAL("VM_KEY", x, ..., fallback), usually through the generated wrappers in L3DRM_Formulas.h. This page lists everything a formula can use. The same reference is available in the formula editor under Functions.

Formulas vs. functions

A formula is what your C++ code calls. A function is a reusable piece of math you use inside formulas; C++ never calls it directly.

FormulaFunction
ExampleVM_THRUST_R1kts_to_ms(v)
Used byYour C++: Formula_THRUST_R1(ias, n1, 0.0)Other formulas and functions, in the portal
Inputs1 to 4, passed by C++ in argument order1 to 4 parameters, passed by the calling formula
In L3DRM_Formulas.hYes, as a wrapperNo
Defined byYour project (Formulas tab)Your project or LAND3 (Functions tab)
// Function (Functions tab)
kts_to_ms(v) = v * 0.514444

// Formula VM_THRUST_R1, inputs ias, n1 (Formulas tab)
clamp(kts_to_ms(ias) * 12.5 + n1 * 0.8, 0, 100)

When you save a formula, every function call is replaced by the function's math, so the delivered formula contains no function calls. If you change a function later, the formulas using it are marked Library changed: open and save them to pick up the change.

Operators and inputs

SyntaxMeaning
+ - * /Arithmetic, usual precedence (* and / before + and -).
-eUnary minus.
( )Grouping.
1.5 .5 1e-3Numeric literals. There is no ^ or pow: use x * x or poly().
x, y, ...Input names: 1 to 4 inputs, passed in DRM_EVAL argument order (arg0..arg3), followed by the fallback.

Built-in functions

FunctionDescriptionRulesExample
min(a, b)Smaller of two expressions.
  • Both arguments are expressions.
  • NaN in either argument gives NaN (unavailable), unlike std::min.
min(x, y)
max(a, b)Larger of two expressions.
  • Both arguments are expressions.
  • NaN in either argument gives NaN (unavailable), unlike std::max.
max(x * 2, 10)
abs(e)Absolute value.
  • The argument is an expression.
abs(x - y)
clamp(e, lo, hi)Limits e to the range lo..hi.
  • lo and hi must be numeric literals (may be negative), not inputs or expressions.
  • lo <= hi.
clamp(x * 0.4375, -10, 100)
poly(e, [c0, c1, c2, ...])Polynomial c0 + c1*e + c2*e^2 + ...
  • Coefficients must be numeric literals.
  • At least 1, at most 64 coefficients.
poly(x, [1, 0.5, 0.25])
lerp1d(e, [xs], [ys])Piecewise linear lookup table.
  • xs and ys are numeric literals of the same length, 2 to 256 points.
  • xs strictly increasing.
  • Outside the table range it holds the end value (no extrapolation).
lerp1d(x, [0, 50, 100], [0, 0.5, 1])
lerp2d(a, b, [xs], [ys], [grid])Bilinear 2D lookup table (a along xs, b along ys).
  • xs, ys: numeric literals, strictly increasing, 2 to 64 points each.
  • grid has xs.length * ys.length literals: all ys values for xs[0] first, then for xs[1], and so on.
  • a and b are clamped to the table range (no extrapolation).
lerp2d(x, y, [0, 100], [0, 10], [0, 1, 2, 3])

Library functions

Besides the built-ins, a formula can call project functions (defined in the Functions tab of your project) and LAND3 functions (shared by LAND3 Simulations for all projects). Both are listed with their bodies in the formula editor and can be inserted from there.

  • Any non-finite intermediate result (division by zero, overflow, NaN) makes the formula unavailable: the wrapper returns its fallback, or NaN.
  • Functions are copied into each formula that uses them: f(a, b) becomes the body of f with a and b filled in.
  • A project function with the same name as a LAND3 function replaces it in your formulas and functions, but not inside LAND3 functions.
  • Builtin names (min, max, abs, clamp, poly, lerp1d, lerp2d) are reserved: no input, parameter or library function may use them.
  • Literal-only positions (clamp bounds, poly coefficients, lerp tables) never accept inputs or parameters.

Limits

LimitValue
Inputs per formula1 to 4
Source length8192 characters
Formula sizeChecked on save; lookup tables and nested function calls count most
Library functions (project + LAND3)64
Parameters per library function1 to 4, each used at least once

Calling formulas from C++

The Formulas tab generates L3DRM_Formulas.h ("Download C++ header") with wrappers for every formula of the project. Inputs are positional, in the order shown in the editor.

#include "L3DRM_Formulas.h"

// Inputs, then the fallback (last): returns the fallback until the formula is available
double ff = Formula_FUEL_FLOW_R1(throttle, rpm, 0.0);

// One formula delivered and valid for this client?
bool one = Formula_FUEL_FLOW_R1_Ready();

// Every formula in the header delivered and valid?
bool all = L3DRM_FormulasReady();

Use a degraded fallback (e.g. reduced output), never the correct value. The fallback is visible in your .wasm and is what runs without activation.

Changing the input order, units or meaning of a shipped formula needs a new key (e.g. _R2): aircraft builds call DRM_EVAL with a fixed argument order.