Skip to main content

Numerical Mapping Functions

This document lists all numerical mapping functions available when integrating the following protocol devices and configuring function points, with detailed descriptions of the syntax and parameters for each function:

Function List

Check the table to find the function you need:

CategoryFunction/Constant NameSyntax & Parameter DescriptionFunction DescriptionTypical Mapping Scenario (Example)
UtilityLinear Mappinglinear(x, inMin, inMax, outMin, outMax)Linearly maps the input value from the original range to the target range.Map ADC raw value [0, 1023] to temperature [-40, 125]: linear(source.value, 0, 1023, -40, 125)
UtilityRange Segmented MappingmapRange(x, thresholds, outputValues)Returns the corresponding discrete value based on which segment the input falls into. thresholds is an ascending array of breakpoints; outputValues length = breakpoints count + 1.Map temperature range to level: mapRange(source.value, [0,20,40], [0,1,2,3])
UtilityDeadband/Hysteresisdeadband(x, center, halfWidth, neutral)Returns a neutral value within [center-halfWidth, center+halfWidth] to suppress minor fluctuations.Filter sensor noise: deadband(source.value, 0, 0.5, 0)
UtilityClampingclamp(x, min, max)Restricts the value within boundaries (uses Math.min/Math.max internally).Limit percentage output range: clamp(source.value, 0, 100)
Power & ExponentialPowerMath.pow(x, y)Returns x to the power of y.Calculate square: Math.pow(source.value, 2)
Power & ExponentialSquare RootMath.sqrt(x)Returns the square root of x.Calculate side length from area.
Power & ExponentialCube RootMath.cbrt(x)Returns the cube root of x.Calculate side length from volume.
Power & ExponentialExponentialMath.exp(x)Returns e raised to the power of x.Linearization fitting for thermistor.
Power & ExponentialHigh Precision exp(x)-1Math.expm1(x)Returns e^x - 1 (precisely handles very small values).High precision small signal amplification.
LogarithmNatural LogarithmMath.log(x)Returns the natural logarithm of x (base e).Audio/signal decibel calculation.
LogarithmCommon LogarithmMath.log10(x)Returns the base 10 logarithm of x.Common: Convert linear value to logarithmic scale (sound pressure level dB).
LogarithmBase-2 LogarithmMath.log2(x)Returns the base 2 logarithm of x.Image/information theory related conversions.
LogarithmHigh Precision log(1+x)Math.log1p(x)Returns ln(1+x) (precisely handles x≈0).Process tiny signals close to zero.
RoundingRoundMath.round(x)Rounds to the nearest integer.Common: Output control value must be an integer.
RoundingFloorMath.floor(x)Rounds down (towards -Infinity).Group number calculation.
RoundingCeilMath.ceil(x)Rounds up (towards +Infinity).Calculate minimal container quantity required.
RoundingTruncateMath.trunc(x)Truncates the decimal part directly (rounds towards zero).Discard decimals, keep integer part only.
RoundingSingle Precision FloatMath.fround(x)Returns the nearest 32-bit single precision float.Simulate low precision floating-point devices (rarely used).
TrigonometricSine/Cosine/TangentMath.sin(x), Math.cos(x), Math.tan(x)Standard trigonometric functions (input in radians).Vibration analysis, angle sensor conversion.
TrigonometricArc Sine/Arc CosineMath.asin(x), Math.acos(x)Returns radians (-π/2 ~ π/2 or 0 ~ π).Reverse phase angle from ratio.
TrigonometricArc TangentMath.atan(x)Returns radians (-π/2 ~ π/2).Calculate slope angle from gradient.
TrigonometricQuadrant Arc TangentMath.atan2(y, x)Returns the angle from X axis to point (x, y) (-π ~ π).Important: Calculate direction angle of resultant vector.
HyperbolicHyperbolic Sine/Cosine/TangentMath.sinh(x), Math.cosh(x), Math.tanh(x)Standard hyperbolic functions.Complex physical models (e.g. catenary calculation).
HyperbolicInverse Hyperbolic FunctionsMath.asinh(x), Math.acosh(x), Math.atanh(x)Inverse hyperbolic functions.Signal filtering modeling.
Extrema & SignAbsolute ValueMath.abs(x)Returns the absolute value.Common: Calculate deviation (actual value vs. target value).
Extrema & SignSign FunctionMath.sign(x)Returns 1, -1, 0 (positive, negative, zero).Judge the direction of value change (up/down).
Extrema & SignMax/MinMath.max(args...), Math.min(args...)Returns the maximum/minimum value among arguments.Common: Used with range limiting.
Geometry & VectorEuclidean NormMath.hypot(x, y, ...)Returns the square root of the sum of the squares of all arguments.Calculate resultant speed or distance in 2D/3D space.
Constantπ (PI)Math.PIPi ≈ 3.14159.Degrees to radians: degrees * Math.PI / 180.
ConstantEuler's NumberMath.EEuler's number ≈ 2.71828.Base for exponentiation.
ConstantLogarithm Base ConstantsMath.LN2 (ln2), Math.LN10 (ln10)Natural logarithms of 2 and 10.Conversion between different logarithmic bases.
ConstantSquare Root ConstantsMath.SQRT2 (√2), Math.SQRT1_2 (1/√2)Common geometry constants.Normalization factor calculation.