Math
Mathematical functions: rounding, powers, logarithms, trigonometry, min, max, average, bitwise operations, special functions such as gamma and erf, and the evaluation of formulas with math eval. Others write numbers in words or Roman numerals and compute VAT. Typical uses: compute a price with tax, write an amount in words on an invoice.
math absmath base_to_basemath acosmath acoshmath asinmath asinhmath atanmath atan2math atanhmath avgmath betamath bit_andmath bit_ormath bit_xormath cbrtmath ceilmath ceilingmath cosmath coshmath cotmath cscmath decimal_formatmath deg_to_radmath emath erfmath erf_invmath erfcmath evalmath evalmath calcmath diffmath diffmath simplifymath expmath expm1math floormath frac_partmath gammamath hypotmath lngammamath logmath log10math log1pmath log_basemath maxmath minmath modmath nrootmath order_intmath order_longmath order_doublemath order_floatmath percentmath pimath powmath powermath rad_to_degmath randommath rintmath roundmath round_sigmath round_uncertaintymath secmath signmath signummath sinmath sinhmath sqrtmath tanmath tanhmath truncmath ulpmath to_wordsmath amount_in_wordsmath romanmath from_romanmath round_bankmath vatmath random_int

math abs <number>


Description

    Get the absolute value of a number

Parameters

    number:   A number - Number - required
admin
math abs -56
mentdb
56
Absolute value of a decimal number
admin
math abs -3.75
mentdb
3.75
A positive number is unchanged
admin
math abs 12
mentdb
12
Distance between two values on a line: |2.5 - 7|
admin
math abs (math eval "2.5-7")
mentdb
4.5
Absolute error of a measure (9.79) against the reference 9.80665
admin
math abs (math eval "9.79-9.80665")
mentdb
0.016650000000000276
Used in use cases (24 recipes)

    Crystallographer & materials physicist › Lattice parameters from an orientation matrix by QR
    Pharmacist & pharmacokinetics › Dissolution profile similarity: f1 and f2 factors
    Geneticist & bioinformatician › Heritability by parent-offspring regression (QR)
    Medical physicist › Triple-isotope SPECT: crosstalk correction by LU
    Agronomist › Pesticide dissipation: SFO and FOMC DT50 / DT90
    Aeronautical engineer › Wind triangle of a flight plan leg and runway wind components
    and 18 more in the Use cases
Often used with

    math sqrt  ·  stat mean  ·  matrix mul  ·  json load select  ·  math log  ·  stat max  ·  stat min  ·  stat pvariance

math base_to_base <number> <fromBase> <toBase>


Description

    Get a number in another base

Parameters

    number:   A number - Number - required
    fromBase:   A number - Number - required
    toBase:   A number - Number - required
admin
math base_to_base 3 10 2
mentdb
11
255 in hexadecimal
admin
math base_to_base 255 10 16
mentdb
ff
Binary to decimal
admin
math base_to_base 101101 2 10
mentdb
45
Decimal to binary
admin
math base_to_base 2024 10 2
mentdb
11111101000
Hexadecimal to decimal (color component ff)
admin
math base_to_base ff 16 10
mentdb
255
Octal Unix permissions 755 to binary
admin
math base_to_base 755 8 2
mentdb
111101101
Base 36
admin
math base_to_base 1000000 10 36
mentdb
lfls
Used in use cases (1 recipe)

    Algorithms in MQL › Fibonacci with a memo stored in a node
Often used with

    and  ·  bi+  ·  case  ·  date current_ms  ·  execute  ·  is not null  ·  node count  ·  node create

math acos <number>


Description

    Get the arc cosine of a number

Parameters

    number:   A number - Number - required
admin
math acos 42
mentdb
NaN
acos(0.5) = pi/3
admin
math acos 0.5
mentdb
1.0471975511965979
acos(-1) = pi
admin
math acos -1
mentdb
3.141592653589793
acos(1) = 0
admin
math acos 1
mentdb
0
Angle between two unit vectors with a dot product of 0.5, in degrees
admin
math rad_to_deg (math acos 0.5)
mentdb
60.00000000000001
acos(0) = pi/2
admin
math acos 0
mentdb
1.5707963267948966
Used in use cases (6 recipes)

    Crystallographer & materials physicist › Symmetry operations: rotation angle, order and the crystallographic restriction
    Space mission engineer › Orbital elements from a state vector
    Renewable energy engineer › Sun angles and plane of array irradiance on a tilted PV panel
    Robotics engineer › Tool orientation: rotation matrix to axis-angle and quaternion
    Space mission engineer › Attitude matrix, Euler angle and inertia tensor
    Renewable energy engineer › Power factor correction of a workshop
Often used with

    math rad_to_deg  ·  math cos  ·  matrix trace  ·  math atan2  ·  math deg_to_rad  ·  math sin  ·  matrix det  ·  matrix get

math acosh <number>


Description

    Get the inverse hyperbolic cosine of a number

Parameters

    number:   A number - Number - required
admin
math acosh 2
mentdb
1.3169578969248166
acosh(1) = 0
admin
math acosh 1
mentdb
0
acosh(10)
admin
math acosh 10
mentdb
2.993222846126381
Inverse of cosh: acosh(cosh(2)) = 2
admin
math acosh (math cosh 2)
mentdb
2
Below 1: NaN
admin
math acosh 0.5
mentdb
NaN
Used in use cases (8 recipes)

    Mathematician › Hyperbolic functions and the Gudermannian
    Physicist › Skydiver with quadratic drag: tanh and acosh
    Nuclear & radiation physicist › Cosmic muons: time dilation in numbers
    Mathematical physicist › Rapidity, Lorentz factor and pseudorapidity
    Space mission engineer › Hyperbolic departure orbit to Mars
    Electronics & signal engineer › Chebyshev type I low-pass: order and poles
    and 2 more in the Use cases
Often used with

    math tanh  ·  math cosh  ·  math sinh  ·  math asinh  ·  math sqrt  ·  unit convert  ·  math atan  ·  math atanh

math asin <number>


Description

    Get the arc sine of a number

Parameters

    number:   A number - Number - required
admin
math asin 0.5
mentdb
0.5235987755982989
asin(1) = pi/2
admin
math asin 1
mentdb
1.5707963267948966
Outside [-1, 1]: NaN
admin
math asin 2
mentdb
NaN
asin(-0.5) = -pi/6
admin
math asin -0.5
mentdb
-0.5235987755982989
Refraction (Snell): angle in water for 30 degrees in air, n = 1.333, in degrees
admin
math rad_to_deg (math asin (math eval "sin(pi/6)/1.333"))
mentdb
22.030108725578987
asin(0) = 0
admin
math asin 0
mentdb
0
Used in use cases (5 recipes)

    Physicist › Total internal reflection and the evanescent wave
    Optics & photonics › Fresnel reflectance and the Brewster angle
    IoT & sensor engineer › 10-minute wind report of a weather station
    Optics & photonics › Fabry-Perot etalon: FSR, finesse and linewidth
    Optics & photonics › Diffraction grating: orders and angles of a spectrum
Often used with

    math rad_to_deg  ·  math sin  ·  math deg_to_rad  ·  complex abs  ·  complex add  ·  complex arg  ·  complex asin  ·  complex cos

math asinh <number>


Description

    Get the inverse hyperbolic sine of a number

Parameters

    number:   A number - Number - required
admin
math asinh 1
mentdb
0.8813735870195429
asinh(0) = 0
admin
math asinh 0
mentdb
0
asinh(-2)
admin
math asinh -2
mentdb
-1.4436354751788103
Inverse of sinh
admin
math asinh (math sinh 1.5)
mentdb
1.5
Large x: ln(2x)
admin
math asinh 1e6
mentdb
14.50865773852447
Used in use cases (5 recipes)

    Mathematician › Hyperbolic functions and the Gudermannian
    Mathematical physicist › Rapidity, Lorentz factor and pseudorapidity
    Electrochemist & battery engineer › PEM electrolyzer: voltage breakdown at 2 A/cm2
    Astronomer › Luminosity distance and lookback time in Lambda-CDM
    Electronics & signal engineer › Chebyshev type I low-pass: order and poles
Often used with

    math acosh  ·  math atanh  ·  math cosh  ·  math sinh  ·  math tanh  ·  atom get  ·  complex im  ·  complex mul

math atan <number>


Description

    Get the arc tangent of a number

Parameters

    number:   A number - Number - required
admin
math atan 42
mentdb
1.5469913006098266
atan(1) = pi/4
admin
math atan 1
mentdb
0.7853981633974483
atan(-1)
admin
math atan -1
mentdb
-0.7853981633974483
atan(0) = 0
admin
math atan 0
mentdb
0
Slope of 10 % in degrees
admin
math rad_to_deg (math atan 0.1)
mentdb
5.710593137499643
Large x: pi/2
admin
math atan 1e12
mentdb
1.5707963267938967
Used in use cases (10 recipes)

    Mathematician › Hyperbolic functions and the Gudermannian
    Math teacher & student › Solve a right triangle and its six trig ratios
    Optics & photonics › Fresnel reflectance and the Brewster angle
    Medical physicist › HDR brachytherapy: TG-43 line-source dose rate
    Agronomist › Field slope, aspect and USLE LS factor from a DEM
    Space mission engineer › Hyperbolic departure orbit to Mars
    and 4 more in the Use cases
Often used with

    math rad_to_deg  ·  math tan  ·  math hypot  ·  math sin  ·  math atan2  ·  math deg_to_rad  ·  math acosh  ·  math cot

math atan2 <number1> <number2>


Description

    Get the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta)

Parameters

    number1:   A number - Number - required
    number2:   A number - Number - required
admin
math atan2 4 2
mentdb
1.1071487177940904
Angle of the point (x = -1, y = 1): 3*pi/4
admin
math atan2 1 -1
mentdb
2.356194490192345
Angle of the point (0, -2)
admin
math atan2 -2 0
mentdb
-1.5707963267948966
Quadrant 3: the point (-1, -1)
admin
math atan2 -1 -1
mentdb
-2.356194490192345
Phase of the complex number 3+4i, in degrees
admin
math rad_to_deg (math atan2 4 3)
mentdb
53.13010235415598
On the negative x axis: pi
admin
math atan2 0 -1
mentdb
3.141592653589793
Used in use cases (20 recipes)

    Math teacher & student › Solve a right triangle and its six trig ratios
    Atomic & quantum physicist › A qubit state on the Bloch sphere
    Mathematical physicist › Flow past a cylinder with circulation
    Crystallographer & materials physicist › Twinning in titanium: the 10-12 twin
    Materials scientist › Principal stresses and safety factors (Mohr circle)
    Medical physicist › HDR brachytherapy: TG-43 line-source dose rate
    and 14 more in the Use cases
Often used with

    math hypot  ·  math rad_to_deg  ·  math deg_to_rad  ·  math sin  ·  math cos  ·  math sqrt  ·  math atan  ·  math sec

math atanh <number>


Description

    Get the inverse hyperbolic tangent of a number

Parameters

    number:   A number - Number - required
admin
math atanh 0.5
mentdb
0.5493061443340549
atanh(0.9)
admin
math atanh 0.9
mentdb
1.4722194895832204
atanh(0) = 0
admin
math atanh 0
mentdb
0
Inverse of tanh
admin
math atanh (math tanh 0.7)
mentdb
0.7000000000000002
At 1: infinity
admin
math atanh 1
mentdb
Infinity
Outside [-1, 1]: NaN (use math calc for the complex value)
admin
math atanh 2
mentdb
NaN
Used in use cases (5 recipes)

    Mathematician › Hyperbolic functions and the Gudermannian
    Physicist › Relativistic velocity addition with rapidities
    Mathematical physicist › Rapidity, Lorentz factor and pseudorapidity
    Biologist & microbiologist › Photosynthesis-irradiance curve (Jassby-Platt)
    Geneticist & bioinformatician › Three-point testcross: interference and map functions
Often used with

    math tanh  ·  math cosh  ·  math sinh  ·  constant physics_c  ·  math acosh  ·  math asinh  ·  atom get  ·  constant physics_e

math avg <json_array>


Description

    Get the average of a JSON array of values

Parameters

    json_array:   A JSON array (of double values) - String - required
admin
math avg "[10 20]"
mentdb
15.0
Average of measurements
admin
math avg "[9.78, 9.82, 9.80, 9.81]"
mentdb
9.8025
Negative values
admin
math avg "[-2, 4, -6, 8]"
mentdb
1.0
One value
admin
math avg "[42]"
mentdb
42.0
Average of the results of a command
admin
math avg (stat zscore "[1, 2, 3, 4, 5]")
mentdb
4.4408920985006264E-17
Used in use cases (26 recipes)

    MQL beginner › Loop over the lines of a JSON order
    Math teacher & student › A class test: mode, frequency table, two variances
    Physicist › Is our pendulum g compatible with standard gravity?
    Thermodynamics & heat transfer › Calibrating thermocouples at the ice point
    Nuclear & radiation physicist › Is the background really Poisson?
    Acoustics engineer › Noise barrier: energy-average Leq and a significance test
    and 20 more in the Use cases
Often used with

    stat mode  ·  stat pvariance  ·  math sqrt  ·  stat frequency  ·  json doc  ·  json iarray  ·  json parse_array  ·  math power

math beta <a> <b>


Description

    Get the Beta function B(a, b) = Gamma(a).Gamma(b)/Gamma(a+b) (a, b > 0)

Parameters

    a:   A number > 0 - Number - required
    b:   A number > 0 - Number - required
admin
math beta 2 3
mentdb
0.08333333333333333
B(0.5, 0.5) = pi
admin
math beta 0.5 0.5
mentdb
3.1415926535897936
B(1, 4) = 1/4
admin
math beta 1 4
mentdb
0.25
Symmetry: B(a, b) = B(b, a)
admin
math beta 4 1
mentdb
0.25
Large arguments
admin
math beta 50 60
mentdb
5.84256439064177E-34
Used in use cases (5 recipes)

    Mathematician › Gamma and Beta: classic identities checked numerically
    Mathematical physicist › Volume of the n-ball with Gamma and Beta
    Geneticist & bioinformatician › Somatic variant call: beta-binomial noise model
    Statistician & biostatistician › The Student t density from the Gamma and Beta functions
    Actuary & risk analyst › Bayesian credibility of a fleet claim rate
Often used with

    math gamma  ·  math power  ·  constant math_pi  ·  math lngamma  ·  math round_sig  ·  arith ncr  ·  atom get  ·  math e

math bit_and <number1> <number2>


Description

    The bitwise AND operation

Parameters

    number1:   A number - Number - required
    number2:   A number - Number - required
admin
math bit_and 4456 234
mentdb
104
Mask the 4 low bits of 0b10111011 (187)
admin
math bit_and 187 15
mentdb
11
Is the number even? (n AND 1 = 0)
admin
math bit_and 1234 1
mentdb
0
Network mask: 192 AND 255
admin
math bit_and 192 255
mentdb
192
Used in use cases (13 recipes)

    MQL developer › User rights as a bitmask
    Mathematician › Winning move in the game of Nim
    Cryptographer & number theorist › Period and balance of an 8-bit LFSR keystream
    Geneticist & bioinformatician › Ts/Tv ratio with 2-bit nucleotide codes
    Telecom & radar engineer › Single error correction with a Hamming (7,4) code
    Robotics engineer › 16-bit encoder rollover and commutation angle
    and 7 more in the Use cases
Often used with

    math bit_or  ·  math bit_xor  ·  math trunc  ·  string lpad  ·  string bin  ·  string int_to_hex  ·  atom get  ·  math power

math bit_or <number1> <number2>


Description

    The bitwise OR operation

Parameters

    number1:   A number - Number - required
    number2:   A number - Number - required
admin
math bit_or 4456 234
mentdb
4586
Set the bit 3 of 5
admin
math bit_or 5 8
mentdb
13
Combine flags 1, 2 and 8
admin
math bit_or (math bit_or 1 2) 8
mentdb
11
Same bits: no change
admin
math bit_or 12 12
mentdb
12
Used in use cases (11 recipes)

    MQL developer › User rights as a bitmask
    Mathematician › Winning move in the game of Nim
    Cryptographer & number theorist › Period and balance of an 8-bit LFSR keystream
    Geneticist & bioinformatician › Ts/Tv ratio with 2-bit nucleotide codes
    Telecom & radar engineer › Single error correction with a Hamming (7,4) code
    Electronics & signal engineer › PRBS7 test pattern from a linear feedback shift register
    and 5 more in the Use cases
Often used with

    math bit_and  ·  math bit_xor  ·  string lpad  ·  math trunc  ·  string bin  ·  string int_to_hex  ·  atom get  ·  math power

math bit_xor <number1> <number2>


Description

    The bitwise XOR operation

Parameters

    number1:   A number - Number - required
    number2:   A number - Number - required
admin
math bit_xor 4456 234
mentdb
4482
XOR twice gives the value back
admin
math bit_xor (math bit_xor 1234 999) 999
mentdb
1234
Bits that differ between 12 (1100) and 10 (1010)
admin
math bit_xor 12 10
mentdb
6
XOR with itself = 0
admin
math bit_xor 255 255
mentdb
0
Used in use cases (12 recipes)

    MQL developer › User rights as a bitmask
    Mathematician › Winning move in the game of Nim
    Cryptographer & number theorist › Two-time pad: breaking a reused one-time key
    Geneticist & bioinformatician › Ts/Tv ratio with 2-bit nucleotide codes
    Telecom & radar engineer › Single error correction with a Hamming (7,4) code
    Electronics & signal engineer › PRBS7 test pattern from a linear feedback shift register
    and 6 more in the Use cases
Often used with

    math bit_and  ·  math bit_or  ·  string lpad  ·  math trunc  ·  string bin  ·  string int_to_hex  ·  atom get  ·  math power

math cbrt <number>


Description

    Returns the cube root of a double value

Parameters

    number:   A number - Number - required
admin
math cbrt 42
mentdb
3.4760266448864496
Cube root of a negative number
admin
math cbrt -27
mentdb
-3
Side of a cube of 2 m3
admin
math cbrt 2
mentdb
1.2599210498948732
Perfect cube
admin
math cbrt 1000
mentdb
10
Radius of a sphere of 1 L (4/3 pi r^3 = 0.001 m3), in m
admin
math cbrt (math eval "0.001*3/(4*pi)")
mentdb
0.06203504908994
Used in use cases (8 recipes)

    Math teacher & student › Simplify an expression, then solve with roots
    Crystallographer & materials physicist › X-ray crystal density and the Avogadro constant
    Chemist › Lattice parameter, X-ray density and crystallite size from XRD
    Corrosion researcher › Deepest pit on a pipe by Gumbel extreme values
    Electrochemist & battery engineer › Electrons transferred in the oxygen reduction (Koutecky-Levich)
    Process & reactor engineer › Agitation scale-up at constant power per volume
    and 2 more in the Use cases
Often used with

    math power  ·  math nroot  ·  const get  ·  math hypot  ·  math round_sig  ·  and  ·  constant physics_n  ·  math eval

math ceil <number>


Description

    Get the smallest integer value not less than the number specified as argument

Parameters

    number:   A number - Number - required
admin
math ceil 1.2
mentdb
2
Negative numbers go toward 0
admin
math ceil -1.2
mentdb
-1
Number of boxes of 12 for 50 items (50/12 = 4.17)
admin
math ceil 4.17
mentdb
5
An integer is unchanged
admin
math ceil 5
mentdb
5
Small decimals
admin
math ceil 0.0001
mentdb
1
Used in use cases (23 recipes)

    Web service developer › Search with sort and pagination
    Math teacher & student › Rounding, truncating and the sign of negative numbers
    Optics & photonics › Diffraction grating: orders and angles of a spectrum
    Thermodynamics & heat transfer › Frost depth for a water main (semi-infinite solid)
    Operations researcher › EOQ, safety stock and reorder point
    Metrologist › Josephson and quantum Hall standards
    and 17 more in the Use cases
Often used with

    math erf_inv  ·  math trunc  ·  math sqrt  ·  json doc  ·  json iarray  ·  math erfc  ·  math min  ·  math power

math ceiling <number>


Description

    Get the smallest integer value not less than the number specified as argument

Parameters

    number:   A number - Number - required
admin
math ceiling 1.2
mentdb
2
Same as math ceil
admin
math ceiling 7.0001
mentdb
8
Negative number
admin
math ceiling -7.9
mentdb
-7
Number of buses of 50 seats for 437 people
admin
math ceiling (math eval "437/50")
mentdb
9
Used in use cases (4 recipes)

    Operations researcher › Call centre staffing with Erlang C
    Process & reactor engineer › Shortcut column design: Fenske, Underwood, Gilliland
    Medical physicist › Linac bunker: primary barrier thickness (NCRP 147)
    Process & reactor engineer › Production campaign planning
Often used with

    math frac_part  ·  math log10  ·  math power  ·  math round_sig  ·  math trunc  ·  num solve  ·  stat dist_cdf  ·  stat dist_pdf

math cos <number>


Description

    Get the cosine of a number

Parameters

    number:   A number - Number - required
admin
math cos 42
mentdb
-0.39998531498835127
cos(0) = 1
admin
math cos 0
mentdb
1
cos(pi) = -1
admin
math cos (math pi)
mentdb
-1
The angle is in radians: 60 degrees
admin
math cos (math deg_to_rad 60)
mentdb
0.5000000000000001
cos(pi/2): almost 0 (rounding of pi)
admin
math cos 1.5707963267948966
mentdb
6.123233995736766E-17
Horizontal component of a force of 100 N at 30 degrees
admin
math eval "100*cos(30)" "{\"_angle\": \"deg\"}"
mentdb
86.60254037844388
Periodicity: cos(2 pi) = 1
admin
math cos (math eval "2*pi")
mentdb
1
Used in use cases (10 recipes)

    Math teacher & student › Solve a right triangle and its six trig ratios
    Crystallographer & materials physicist › Lattice parameters from an orientation matrix by QR
    Space mission engineer › Attitude matrix, Euler angle and inertia tensor
    Renewable energy engineer › Power factor correction of a workshop
    Control engineer › Time-domain specs from the closed-loop poles
    Robotics engineer › Rotation matrix of a tool from ZYX Euler angles
    and 4 more in the Use cases
Often used with

    math sin  ·  math atan2  ·  math hypot  ·  math acos  ·  math rad_to_deg  ·  math sqrt  ·  matrix det  ·  matrix get

math cosh <number>


Description

    Get the hyperbolic cosine of a number

Parameters

    number:   A number - Number - required
admin
math cosh 42
mentdb
8.696374707602505E17
cosh(0) = 1
admin
math cosh 0
mentdb
1
cosh(1)
admin
math cosh 1
mentdb
1.543080634815244
Catenary: height of a chain y = a cosh(x/a) for a = 2, x = 1
admin
math eval "2*cosh(1/2)"
mentdb
2.2552519304127614
Even function: cosh(-1) = cosh(1)
admin
math cosh -1
mentdb
1.543080634815244
Used in use cases (6 recipes)

    Mathematician › Hyperbolic functions and the Gudermannian
    Physicist › Relativistic velocity addition with rapidities
    Thermodynamics & heat transfer › Aluminium pin fin: heat rate, efficiency, tip temperature
    Mathematical physicist › Rapidity, Lorentz factor and pseudorapidity
    Mechanical & civil engineer › Sag, length and tension of a suspended cable (catenary)
    Sales & marketing analyst › Saturating media response and the optimal spend
Often used with

    math tanh  ·  math acosh  ·  math sinh  ·  math atanh  ·  constant physics_c  ·  math asinh  ·  math sqrt  ·  string regexp_extract

math cot <number>


Description

    Get the cotangent of a number

Parameters

    number:   A number - Number - required
admin
math cot 42
mentdb
0.4364167060752729
cot(pi/4) = 1
admin
math cot 0.7853981633974483
mentdb
1.0000000000000002
cot(pi/2) = 0 (almost)
admin
math cot 1.5707963267948966
mentdb
6.123233995736766E-17
cot(1) = 1/tan(1)
admin
math cot 1
mentdb
0.6420926159343306
Used in use cases (5 recipes)

    Math teacher & student › Solve a right triangle and its six trig ratios
    Mathematical physicist › Rapidity, Lorentz factor and pseudorapidity
    Geologist & seismologist › Palaeolatitude and virtual geomagnetic pole of a lava flow
    Telecom & radar engineer › Radiation resistance and efficiency of a short CB whip
    Mechanical & civil engineer › Member forces of a triangular roof truss by the method of joints
Often used with

    math tan  ·  constant physics_c  ·  math atan  ·  math atan2  ·  math csc  ·  math hypot  ·  math rad_to_deg  ·  math sec

math csc <number>


Description

    Get the cosecant (1/sin) of a number

Parameters

    number:   A number - Number - required
admin
math csc 1.5707963267948966
mentdb
1
csc(pi/6) = 2
admin
math csc 0.5235987755982988
mentdb
2.0000000000000004
csc(1) = 1/sin(1)
admin
math csc 1
mentdb
1.1883951057781212
csc(0): infinite
admin
math csc 0
mentdb
Infinity
Used in use cases (3 recipes)

    Math teacher & student › Solve a right triangle and its six trig ratios
    Robotics engineer › Tool orientation: rotation matrix to axis-angle and quaternion
    Mechanical & civil engineer › Member forces of a triangular roof truss by the method of joints
Often used with

    math atan2  ·  math cos  ·  math cot  ·  math hypot  ·  math sec  ·  math sin  ·  math tan  ·  math acos

math decimal_format <number> <pattern> <decimalSeparator> <groupingSeparator>


Description

    Convert a number to another formatted decimal number

Parameters

    number:   A number - Number - required
    pattern:   The pattern - String - required
    decimalSeparator:   The decimal separator - String - required
    groupingSeparator:   The grouping separator - String - required
admin
math decimal_format 42.456 "##.##" "." " "
mentdb
42.46
Thousands separator and 2 decimals
admin
math decimal_format 1234567.891 "#,##0.00" "," " "
mentdb
1 234 567,89
Percentage
admin
math decimal_format 0.256 "0.0%" "." ","
mentdb
25.6%
Fixed 3 decimals
admin
math decimal_format 3.14159 "0.000" "." ","
mentdb
3.142
Leading zeros
admin
math decimal_format 42 "00000" "." ","
mentdb
00042
Scientific notation
admin
math decimal_format 0.000123456 "0.00E0" "." ","
mentdb
1.23E-4
Currency with a French separator
admin
math decimal_format 1234.5 "#,##0.00 EUR" "," " "
mentdb
1 234,50 EUR
Used in use cases (4 recipes)

    Data quality analyst › Gaps and duplicates in an invoice number sequence
    PDF & document automation specialist › A4 invoice with a table, totals and page numbers
    Files & archives manager › Mainframe fixed-width file to CSV with implied decimals
    PDF & document automation specialist › Monthly statements: one file, then one PDF per customer
Often used with

    pdf close  ·  pdf create  ·  pdf draw rect  ·  pdf extract_text  ·  pdf page add  ·  pdf page_count_file  ·  pdf page_number add  ·  pdf save

math deg_to_rad <number>


Description

    Converts an angle measured in degrees to an approximately equivalent angle measured in radians

Parameters

    number:   A number - Number - required
admin
math deg_to_rad 42
mentdb
0.7330382858376184
180 degrees = pi radians
admin
math deg_to_rad 180
mentdb
3.141592653589793
90 degrees
admin
math deg_to_rad 90
mentdb
1.5707963267948966
Full turn: 2 pi
admin
math deg_to_rad 360
mentdb
6.283185307179586
Negative angle
admin
math deg_to_rad -45
mentdb
-0.7853981633974483
1 degree
admin
math deg_to_rad 1
mentdb
0.017453292519943295
Used in use cases (14 recipes)

    Physicist › Total internal reflection and the evanescent wave
    Optics & photonics › Fresnel reflectance and the Brewster angle
    Astronomer › Sunrise, sunset and equation of time at the winter solstice
    Space mission engineer › Slant range, elevation and pass duration over a ground station
    Aeronautical engineer › Wind triangle of a flight plan leg and runway wind components
    Meteorologist › Vector mean wind, steadiness and wind rose of a station
    and 8 more in the Use cases
Often used with

    math rad_to_deg  ·  math atan2  ·  math hypot  ·  math tan  ·  complex abs  ·  complex add  ·  complex arg  ·  complex div

math e


Description

    Get the approximate value of Euler's number.

admin
math e
mentdb
2.718281828459045
e^2 with math pow
admin
math pow (math e) 2
mentdb
7.3890560989306495
ln(e) = 1
admin
math log (math e)
mentdb
1
Continuous compounding: 1000 at 5 % for 10 years
admin
math eval "1000*e^(0.05*10)"
mentdb
1648.7212707001281
Used in use cases (2 recipes)

    Mathematician › Gamma and Beta: classic identities checked numerically
    Epidemiologist › Incubation period and quarantine length
Often used with

    math round_sig  ·  constant math_pi  ·  math beta  ·  math ceil  ·  math erf_inv  ·  math erfc  ·  math exp  ·  math gamma

math erf <number>


Description

    Get the error function erf(x)

Parameters

    number:   A number - Number - required
admin
math erf 1
mentdb
0.8427007929497151
erf(0) = 0
admin
math erf 0
mentdb
0
Probability that a normal value is within 2 standard deviations: erf(2/sqrt(2))
admin
math erf 1.4142135623730951
mentdb
0.9544997361036417
Odd function: erf(-1) = -erf(1)
admin
math erf -1
mentdb
-0.8427007929497151
Large x: 1
admin
math erf 5
mentdb
0.9999999999984626
Normal law: P(-1 < Z < 1) = erf(1/sqrt(2))
admin
math erf 0.7071067811865476
mentdb
0.6826894921370861
Used in use cases (11 recipes)

    Physicist › Fraction of fast molecules in a Maxwell gas
    Optics & photonics › Measuring a Gaussian beam with a knife edge
    Thermodynamics & heat transfer › Frost depth for a water main (semi-infinite solid)
    Nuclear & radiation physicist › HPGe gamma peak: resolution, ROI and detection limit
    Operations researcher › EOQ, safety stock and reorder point
    Metrologist › Lab bias on a certified reference material
    and 5 more in the Use cases
Often used with

    math erf_inv  ·  math sqrt  ·  math erfc  ·  math log  ·  constant math_pi  ·  math ceil  ·  string regexp_extract  ·  unit convert

math erf_inv <number>


Description

    Get the inverse error function (x in ]-1, 1[)

Parameters

    number:   A number - Number - required
admin
math erf_inv 0.5
mentdb
0.47693627620446977
Inverse of erf(1)
admin
math erf_inv 0.8427007929497149
mentdb
0.9999999999999998
erf_inv(0) = 0
admin
math erf_inv 0
mentdb
0
erf_inv(-0.5)
admin
math erf_inv -0.5
mentdb
-0.47693627620446977
Close to 1
admin
math erf_inv 0.999999
mentdb
3.458910737275499
Outside ]-1, 1[
admin
math erf_inv 1.5
mentdb
Sorry, an error appears (erf_inv is defined for x in ]-1, 1[).
Used in use cases (18 recipes)

    Optics & photonics › Measuring a Gaussian beam with a knife edge
    Thermodynamics & heat transfer › Frost depth for a water main (semi-infinite solid)
    Nuclear & radiation physicist › HPGe gamma peak: resolution, ROI and detection limit
    Operations researcher › EOQ, safety stock and reorder point
    Metrologist › Lab bias on a certified reference material
    Mathematical physicist › Sudden heating of a thick steel slab
    and 12 more in the Use cases
Often used with

    math erfc  ·  math sqrt  ·  math erf  ·  math ceil  ·  math round_sig  ·  stat mean  ·  math log  ·  math power

math erfc <number>


Description

    Get the complementary error function erfc(x) = 1 - erf(x)

Parameters

    number:   A number - Number - required
admin
math erfc 1
mentdb
0.15729920705028488
erfc(3): no cancellation for the small values
admin
math erfc 3
mentdb
2.2090496998585448E-5
erfc(0) = 1
admin
math erfc 0
mentdb
1
erfc(x) = 1 - erf(x)
admin
math erfc 0.5
mentdb
0.47950012218695337
Negative x: up to 2
admin
math erfc -2
mentdb
1.9953222650189528
Very small values without underflow
admin
math erfc 10
mentdb
2.0884875837625685E-45
Used in use cases (17 recipes)

    Physicist › Fraction of fast molecules in a Maxwell gas
    Optics & photonics › Measuring a Gaussian beam with a knife edge
    Metrologist › Lab bias on a certified reference material
    Mathematical physicist › Sudden heating of a thick steel slab
    Materials scientist › Carburizing time for a given case depth
    Process & reactor engineer › Process capability of an API assay
    and 11 more in the Use cases
Often used with

    math erf_inv  ·  math sqrt  ·  math erf  ·  stat mean  ·  math round_sig  ·  math ceil  ·  math exp  ·  math log

math eval <expression>


Description

    Evaluate a mathematical expression.
Expression syntax (also used by the 'num' functions):
- operators: + - * / ^ (or **), parentheses; ^ is right associative (2^3^2 = 512) and -x^2 = -(x^2)
- numbers: 12, 1.5, .5, 1e-3; constants: pi, e
- functions: sin cos tan sec csc cot asin acos atan sinh cosh tanh asinh acosh atanh (radians), exp expm1 ln (natural) log log10 (base 10) log1p sqrt cbrt abs floor ceil round sign deg_to_rad rad_to_deg, atan2(y,x) pow(x,y) hypot(x,y) min(a,b) max(a,b) mod(a,b) log_base(x,b)
- parts of a complex number (math calc): re im arg conj; special functions (see the page Special functions): bessel_j bessel_y bessel_i bessel_k sph_bessel_j sph_bessel_y legendre assoc_legendre hermite laguerre chebyshev_t chebyshev_u gamma lgamma digamma polygamma beta gamma_inc gamma_incc beta_inc erf erfc erf_inv zeta
- variables: names made of letters, digits and _ (case sensitive); the multiplication must be written (2*x, not 2x)
- the expressions are compiled once and kept in a cache

Parameters

    expression:   The expression - String - required
admin
math eval "2+3*4"
mentdb
14
admin
math eval "sqrt(16)+2^10"
mentdb
1028
Operator precedence and powers
admin
math eval "2^3^2"
mentdb
512
Functions and constants
admin
math eval "sqrt(2)*sin(pi/4)"
mentdb
1
Special functions
admin
math eval "gamma(0.5)^2"
mentdb
3.1415926535897936
Scientific notation
admin
math eval "6.022e23*1.5e-3"
mentdb
9.033E20
Parentheses
admin
math eval "(1+2)*(3+4)"
mentdb
21
Unary minus and power: -2^2 = -4
admin
math eval "-2^2"
mentdb
-4
Logarithms: ln, log (base 10), log_base
admin
math eval "ln(e^3)+log(1000)+log_base(8, 2)"
mentdb
9
Hyperbolic functions
admin
math eval "cosh(1)^2-sinh(1)^2"
mentdb
1.0000000000000007
CODATA constants (with math calc): energy of 1 mol of photons of 500 nm in J
admin
math calc "_NA*_h*_c/500e-9"
mentdb
239253.13127739402
Rounding functions
admin
math eval "floor(2.7)+ceil(2.1)+round(2.5)"
mentdb
7
Golden ratio
admin
math eval "(1+sqrt(5))/2"
mentdb
1.618033988749895
Error: unknown function
admin
math eval "foo(2)"
mentdb
Sorry, an error appears (unknown function 'foo' at position 1 in 'foo(2)').

math eval <expression> <json_vars>


Description

    Evaluate a mathematical expression with variables (JSON object of numbers).
See 'math eval expression' for the syntax.
Option "_angle": "rad" (default), "deg" or "grad": unit of sin, cos, tan, sec, csc, cot (argument) and of asin, acos, atan, atan2 (result). In degrees and grads, the remarkable angles give exact values (sin 30 = 0.5, tan 45 = 1).

Parameters

    expression:   The expression - String - required
    json_vars:   A JSON object: the value of each variable - String - required
admin
math eval "a*x^2+b" "{\"a\": 2, \"x\": 3, \"b\": 1}"
mentdb
19
admin
math eval "sin(30)+asin(0.5)" "{\"_angle\": \"deg\"}"
mentdb
30.5
Kinetic energy E = m v^2 / 2
admin
math eval "m*v^2/2" "{\"m\": 1200, \"v\": 27.8}"
mentdb
463704
Angles in degrees with the option _angle
admin
math eval "sin(a)^2+cos(a)^2" "{\"a\": 30, \"_angle\": \"deg\"}"
mentdb
1
Pendulum period T = 2 pi sqrt(L/g)
admin
math eval "2*pi*sqrt(L/g)" "{\"L\": 0.75, \"g\": 9.81}"
mentdb
1.7373047071809469
Ideal gas: pressure p = nRT/V in Pa (R written as a variable)
admin
math eval "n*R*T/V" "{\"n\": 2, \"R\": 8.314462618, \"T\": 300, \"V\": 0.05}"
mentdb
99773.551416
Compound interest
admin
math eval "C*(1+r)^n" "{\"C\": 1000, \"r\": 0.04, \"n\": 10}"
mentdb
1480.2442849183444
Body mass index
admin
math eval "m/h^2" "{\"m\": 72, \"h\": 1.78}"
mentdb
22.724403484408533
Several variables with special functions
admin
math eval "bessel_j(n, k*r)" "{\"n\": 1, \"k\": 2.405, \"r\": 0.8}"
mentdb
0.5804625562292492
Angle unit grad
admin
math eval "sin(x)" "{\"x\": 100, \"_angle\": \"grad\"}"
mentdb
1
Error: a variable has no value
admin
math eval "a*x+b" "{\"a\": 2, \"x\": 3}"
mentdb
Sorry, an error appears (the variable 'b' is not defined).
Used in use cases (32 recipes)

    Mathematician › Critical points of a function of two variables
    Math teacher & student › Simplify an expression, then solve with roots
    Physicist › Period of a pendulum at large amplitude
    Optics & photonics › Step-index fiber: critical angle, NA and V number
    Atomic & quantum physicist › Harmonic oscillator wave function n = 3
    Acoustics engineer › Adding noise sources and exposure time
    and 26 more in the Use cases
Often used with

    num solve  ·  stat fit  ·  unit convert  ·  json load select  ·  num integrate  ·  bigdec div  ·  math round_sig  ·  unit calc

math calc <expression>


Description

    Calculator: evaluate a mathematical expression with the session variables (used by the CALC tab of the editor).
See 'math eval expression' for the syntax.
- the session variables are written like in MQL: [x], [var1]; they must contain a number: -> "[r]" 2; math calc "pi*[r]^2"
- a name _c, _h, _me... is a CODATA constant (see 'const list'); pi and e are the mathematical constants
- the session variable [_angle] gives the unit of the trigonometric functions: rad (default), deg or grad
- the result is also stored in the session variable [ans], so the next calculation can use [ans]
- complex numbers: i is the imaginary unit (3+4i, (1+2i)*(3-i), exp(i*pi)), with re, im, abs, arg, conj; an expression without a real value gives its complex value (sqrt(-4) = 2i, ln(-1) = 3.141592653589793i), as Python cmath
- the session variable [_format] gives the display format: auto (default), fix n (n decimals), sci n (n significant digits, 1.235E-4), eng n (exponent multiple of 3, 123.5E-6); [ans] keeps all the digits

Parameters

    expression:   The expression - String - required
admin
math calc "sqrt(16)+2^10"
mentdb
1028
admin
math calc "[ans]/4"
mentdb
257
Complex numbers: i is the imaginary unit
admin
math calc "(3+4i)*(1-2i)"
mentdb
11-2i
No real value: the complex value (as Python cmath)
admin
math calc "sqrt(-4)"
mentdb
2i
Euler identity
admin
math calc "exp(i*pi)"
mentdb
-1
Impedance of R = 100 ohm, L = 0.1 H at 50 Hz: modulus
admin
-> "[Z]" (math calc "100+2*3.141592653589793*50*0.1i"); math calc "abs([Z])"
mentdb
104.81870272097883
Display format: 4 significant digits
admin
-> "[_format]" "sci 4"; math calc "_h*_c/500e-9"
mentdb
3.973E-19
Display format: 2 decimals
admin
-> "[_format]" "fix 2"; math calc "1234567.891"
mentdb
1234567.89
Back to the full display
admin
-> "[_format]" "auto"; -> "[_angle]" "rad"; math calc "[ans]"
mentdb
1234567.891
With session variables
admin
-> "[r]" 0.5; math calc "pi*[r]^2"
mentdb
0.7853981633974483
With CODATA constants: energy of a photon of 500 nm in J
admin
math calc "_h*_c/500e-9"
mentdb
3.972891714297857E-19
The last result is in [ans]
admin
math calc "2^10"; math calc "[ans]/4"
mentdb
256
Complex modulus and argument (radians)
admin
math calc "abs(1+i)"
mentdb
1.4142135623730951
Argument of -1 in degrees
admin
-> "[_angle]" "deg"; math calc "arg(-1)"
mentdb
180
Back to radians
admin
-> "[_angle]" "rad"; math calc "arg(i)"
mentdb
1.5707963267948966
Real and imaginary parts
admin
math calc "re((1+2i)^2)+im((1+2i)^2)"
mentdb
1
Conjugate: z * conj(z) = |z|^2
admin
math calc "(3+4i)*conj(3+4i)"
mentdb
25
Square roots of a negative number
admin
math calc "sqrt(-2)"
mentdb
1.4142135623730951i
Logarithm of a negative number
admin
math calc "ln(-10)"
mentdb
2.302585092994046+3.141592653589793i
Complex power
admin
math calc "(1+i)^10"
mentdb
32i
i^i is a real number
admin
math calc "i^i"
mentdb
0.20787957635076193
Engineering format: exponent multiple of 3
admin
-> "[_format]" "eng 3"; math calc "0.000123456"
mentdb
123E-6
Format of a complex result
admin
-> "[_format]" "fix 3"; math calc "exp(i)"
mentdb
0.540+0.841i
Back to the full display
admin
-> "[_format]" "auto"; math calc "exp(i)"
mentdb
0.5403023058681398+0.8414709848078965i
Store a result in a session variable, then use it
admin
-> "[v0]" (math calc "sqrt(2*_g0*20)"); math calc "[v0]*3.6"
mentdb
71.30054249442986
Worked example: Alternating current: an RLC circuit with complex numbers (R = 100 ohm, L = 0.2 H and C = 10 uF in series, under 230 V at 50 Hz. The impedance is a complex number Z = R + i(L w - 1/(C w)): math calc computes with i, abs and arg; [_angle] gives the phase in degrees.)
admin
#Worked example: Alternating current: an RLC circuit with complex numbers; #The values in session variables; -> "[R]" 100; -> "[L]" 0.2; -> "[C]" 0.00001; -> "[w]" (math calc "2*pi*50"); math calc "[w]"; #Impedance Z; -> "[Z]" (math calc "[R]+i*([L]*[w]-1/([C]*[w]))"); math calc "[Z]"; #Modulus |Z| in ohm; math calc "abs([Z])"; #Phase of Z in degrees (negative: the circuit is capacitive); -> "[_angle]" "deg"; math calc "arg([Z])"; #Current (rms) I = U / |Z| in A; -> "[_angle]" "rad"; math calc "230/abs([Z])"; #Resonance frequency f0 = 1 / (2 pi sqrt(L C)) with the units; unit calc "1/(2*pi*sqrt(0.2 H * 10 uF))" "Hz"; #Active power P = R I^2 in W; math calc "[R]*(230/abs([Z]))^2"; #Display with 4 significant digits; -> "[_format]" "sci 4"; math calc "[R]*(230/abs([Z]))^2"; #Back to the full display; -> "[_format]" "auto"; math calc "[ans]";
mentdb
70.28123416893709
Used in use cases (355 recipes)

    Date & time developer › French public holidays and a delivery date in working days
    Mathematician › A toy RSA key, end to end
    Math teacher & student › Solve a quadratic equation, exact and decimal
    Physicist › Period of a pendulum at large amplitude
    Optics & photonics › Step-index fiber: critical angle, NA and V number
    Thermodynamics & heat transfer › U-value and heat loss of an insulated wall
    and 349 more in the Use cases
Often used with

    unit convert  ·  math round_sig  ·  num solve  ·  unit calc  ·  json load select  ·  string regexp_extract  ·  math sqrt  ·  stat mean

math diff <expression> <variable>


Description

    Symbolic derivative of an expression with respect to a variable (the result is an expression, simplified).
- same syntax as 'math eval', with the special functions; the other variables, the session variables [a] and the constants _c, pi, e stay as symbols
- the trigonometric functions are in radians
- the parameters of the special functions (order of bessel_j, degree of legendre...) must not depend on the variable; zeta, min and max have no derivative rule (use 'num derivative' for a value)

Parameters

    expression:   The expression - String - required
    variable:   The variable, ex: x, t, [v] - String - required
admin
math diff "x^2*sin(x)" "x"
mentdb
2*x*sin(x) + x^2*cos(x)
admin
math diff "a*exp(-k*t)" "t"
mentdb
-a*k*exp(-k*t)
Chain rule
admin
math diff "sin(x^2)" "x"
mentdb
2*x*cos(x^2)
Quotient
admin
math diff "x/(x^2+1)" "x"
mentdb
1/(x^2 + 1) - 2*x^2/(x^2 + 1)^2
With other symbols and the constants
admin
math diff "a*exp(-k*t)*cos(w*t)" "t"
mentdb
-a*k*exp(-k*t)*cos(w*t) - a*w*exp(-k*t)*sin(w*t)
Special functions
admin
math diff "bessel_j(0, k*r)" "r"
mentdb
-k*bessel_j(1, k*r)
Power with a variable exponent
admin
math diff "x^x" "x"
mentdb
x^x*(ln(x) + 1)
Logarithm
admin
math diff "ln(x^2+1)" "x"
mentdb
2*x/((x^2 + 1))
Inverse trigonometric function
admin
math diff "atan(x)" "x"
mentdb
1/(x^2 + 1)
Velocity from a position x(t)
admin
math diff "5*t^2+2*t+1" "t"
mentdb
10*t + 2
Partial derivative with respect to y
admin
math diff "x^2*y+y^3" "y"
mentdb
x^2 + 3*y^2
Square root
admin
math diff "sqrt(1-x^2)" "x"
mentdb
-x/sqrt(1 - x^2)
Error function (Gaussian)
admin
math diff "erf(x)" "x"
mentdb
2*exp(-x^2)/sqrt(pi)
Worked example: Symbolic and numerical calculus together (The derivative of f(x) = x^3 e^(-x) is computed symbolically; its zero is the maximum of f; the integral of f is computed numerically.)
admin
#Worked example: Symbolic and numerical calculus together; #f'(x); math diff "x^3*exp(-x)" "x"; #Zero of f' between 1 and 5; num solve "3*x^2*exp(-x) - x^3*exp(-x)" "x" 1 5; #Maximum of f (direct); num maximize "x^3*exp(-x)" "x" 0 10; #Integral of f from 0 to infinity = 3! = 6; num integrate "x^3*exp(-x)" "x" 0 "inf";
mentdb
6

math diff <expression> <variable> <order>


Description

    Symbolic derivative of order n (0 to 20) of an expression with respect to a variable

Parameters

    expression:   The expression - String - required
    variable:   The variable, ex: x, t, [v] - String - required
    order:   The order of the derivative (integer from 0 to 20) - Number - required
admin
math diff "exp(-x^2)" "x" 2
mentdb
-2*exp(-x^2) + 4*x^2*exp(-x^2)
admin
math diff "x^5" "x" 3
mentdb
60*x^2
Second derivative of the Gaussian
admin
math diff "exp(-x^2/2)" "x" 2
mentdb
-exp(-x^2/2) + x^2*exp(-x^2/2)
Third derivative of a polynomial
admin
math diff "x^5-3*x^2" "x" 3
mentdb
60*x^2
Acceleration from a position
admin
math diff "5*t^3-2*t" "t" 2
mentdb
30*t
Fourth derivative of sin: sin
admin
math diff "sin(x)" "x" 4
mentdb
sin(x)
Order 0: the expression
admin
math diff "x^2+1" "x" 0
mentdb
x^2 + 1
Used in use cases (3 recipes)

    Mathematician › Critical points of a function of two variables
    Math teacher & student › Study a function: derivative and table of values
    Mathematical physicist › Quantum harmonic oscillator with Hermite polynomials
Often used with

    cas solve  ·  math eval  ·  arith factorial  ·  cas factor  ·  cas simplify  ·  json load select  ·  num derivative2  ·  num integrate

math simplify <expression>


Description

    Simplify an expression: numbers computed, like terms and powers of the same base grouped (x+x = 2*x, x^2*x = x^3), x^0 = 1, x^1 = x, 0*x = 0...
No trigonometric identity and no factorization: the form stays close to the expression given

Parameters

    expression:   The expression - String - required
admin
math simplify "x+x+2*x"
mentdb
4*x
admin
math simplify "x^2*x/x^3+0*y"
mentdb
1
Like powers
admin
math simplify "x^2*x^3/x"
mentdb
x^4
Numbers and like terms
admin
math simplify "2*x+3+x-1"
mentdb
3*x + 2
Multiplication by 1 and addition of 0
admin
math simplify "1*x+0"
mentdb
x
Constant folding
admin
math simplify "2*3*x+4/2"
mentdb
6*x + 2
Same terms with a coefficient
admin
math simplify "3*x^2-x^2"
mentdb
2*x^2
A derivative made simpler
admin
math simplify (math diff "x^3+2*x" "x")
mentdb
3*x^2 + 2
Used in use cases (2 recipes)

    Math teacher & student › Simplify an expression, then solve with roots
    Mathematical physicist › Legendre polynomials from a QR decomposition
Often used with

    json load select  ·  math cbrt  ·  math eval  ·  math nroot  ·  math power  ·  math sqrt  ·  matrix col  ·  matrix get

math exp <number>


Description

    Returns Euler's number e raised to the power of a double value

Parameters

    number:   A number - Number - required
admin
math exp 42
mentdb
1.73927494152050099E18
exp(1) = e
admin
math exp 1
mentdb
2.718281828459045
Radioactive decay: fraction left after 2 half-lives, exp(-2 ln 2)
admin
math exp -1.3862943611198906
mentdb
0.25
exp(0) = 1
admin
math exp 0
mentdb
1
Inverse of ln
admin
math exp (math log 5)
mentdb
4.999999999999999
Very negative: 0 (underflow)
admin
math exp -800
mentdb
0
Population growth: N0 = 100, r = 0.3 per hour, after 10 h
admin
math eval "100*exp(0.3*10)"
mentdb
2008.5536923187667
Used in use cases (30 recipes)

    Physicist › Skydiver with quadratic drag: tanh and acosh
    Nuclear & radiation physicist › Neutron activation of a gold foil
    Atomic & quantum physicist › Electron tunnelling through a rectangular barrier
    Advanced physical chemist › Consecutive reactions A to B to C by eigen-decomposition
    Process & reactor engineer › Fit Arrhenius parameters with a global optimizer
    Pharmacist & pharmacokinetics › Shelf life from accelerated stability (Arrhenius)
    and 24 more in the Use cases
Often used with

    math sqrt  ·  math log  ·  math round_sig  ·  math power  ·  math expm1  ·  matrix mul  ·  string regexp_extract  ·  json doc

math expm1 <number>


Description

    Returns e^x - 1

Parameters

    number:   A number - Number - required
admin
math expm1 42
mentdb
1.73927494152050099E18
Small x: exp(x) - 1 without cancellation
admin
math expm1 1e-10
mentdb
1.00000000005E-10
expm1(0) = 0
admin
math expm1 0
mentdb
0
expm1(1) = e - 1
admin
math expm1 1
mentdb
1.718281828459045
Negative values
admin
math expm1 -1e-8
mentdb
-9.999999950000001E-9
Used in use cases (13 recipes)

    Mathematician › Machine epsilon and catastrophic cancellation
    Thermodynamics & heat transfer › Counterflow exchanger: effectiveness-NTU checked by LMTD
    Nuclear & radiation physicist › Neutron activation of a gold foil
    Metrologist › Floating-point resolution of time stamps and frequency offsets
    Advanced physical chemist › Heat capacity of diamond: Einstein vs Debye
    Pharmacist & pharmacokinetics › Shelf life from accelerated stability (Arrhenius)
    and 7 more in the Use cases
Often used with

    math log1p  ·  math log  ·  math exp  ·  math power  ·  math round_sig  ·  json load select  ·  math ulp  ·  unit convert

math floor <number>


Description

    Get the largest integer value not greater than the number specified as argument

Parameters

    number:   A number - Number - required
admin
math floor 1.2
mentdb
1
Negative numbers go away from 0
admin
math floor -1.2
mentdb
-2
An integer is unchanged
admin
math floor 3
mentdb
3
Number of whole hours in 200 minutes
admin
math floor (math eval "200/60")
mentdb
3
Used in use cases (7 recipes)

    Math teacher & student › Rounding, truncating and the sign of negative numbers
    Metrologist › Type A and Type B uncertainty of a resistance measurement
    IoT & sensor engineer › Battery life of a LoRaWAN sensor node
    Deep learning engineer › A neural network learns the XOR truth table
    System administrator & DevOps › When will the disk be full?
    Cluster & high-availability engineer › Availability, MTTR, MTBF and SLA of a 2-node cluster
    and 1 more in the Use cases
Often used with

    date add  ·  stat mean  ·  date is_weekend  ·  date nb_business_days  ·  date nb_day  ·  date next_day  ·  date sysdate  ·  date week_of_year

math frac_part <number>


Description

    Get the fractional part x - trunc(x), same sign as x (computed in decimal)

Parameters

    number:   A number - Number - required
admin
math frac_part 3.14
mentdb
0.14
Fractional part of a negative number
admin
math frac_part -2.75
mentdb
-0.75
An integer: 0
admin
math frac_part 8
mentdb
0
Decimal part of a duration of 2.25 h
admin
math frac_part 2.25
mentdb
0.25
Used in use cases (11 recipes)

    MQL beginner › Split a bill: functions inside functions
    String & encoding developer › Mail merge: fill a template from JSON data
    Math teacher & student › Rounding, truncating and the sign of negative numbers
    Metrologist › Floating-point resolution of time stamps and frequency offsets
    Process & reactor engineer › Production campaign planning
    Astronomer › Julian date, sidereal time and Moon age of an observing night
    and 5 more in the Use cases
Often used with

    math trunc  ·  math rint  ·  math sign  ·  math abs  ·  math signum  ·  math ulp  ·  string lpad  ·  bd*

math gamma <number>


Description

    Get the Gamma function (gamma(n) = (n-1)! for the integers). The result is a double: exact for the integers up to 22, about 16 significant digits after, Infinity above 171. For exact factorials, use arith factorial. Not defined for 0 and the negative integers.

Parameters

    number:   A number - Number - required
admin
math gamma 5
mentdb
24
admin
math gamma 0.5
mentdb
1.772453850905516
gamma(n+1) = n!
admin
math gamma 11
mentdb
3628800
gamma(1) = 1
admin
math gamma 1
mentdb
1
Half integers: gamma(2.5) = 3 sqrt(pi)/4
admin
math gamma 2.5
mentdb
1.329340388179137
Poles: 0, -1, -2...
admin
math gamma -2
mentdb
Sorry, an error appears (the Gamma function is not defined for 0 and the negative integers).
Used in use cases (10 recipes)

    Mathematician › Gamma and Beta: classic identities checked numerically
    Nuclear & radiation physicist › Is the background really Poisson?
    Cryptographer & number theorist › Key space and unicity distance of classical ciphers
    Operations researcher › Weibull bearing: age replacement policy
    Mathematical physicist › Volume of the n-ball with Gamma and Beta
    Chemist › Isotope pattern of a tetrachloro compound in MS
    and 4 more in the Use cases
Often used with

    math power  ·  math lngamma  ·  math beta  ·  constant math_pi  ·  math exp  ·  math sqrt  ·  num integrate  ·  stat frequency

math hypot <number1> <number2>


Description

    Returns sqrt(x^2 + y^2) without intermediate overflow or underflow

Parameters

    number1:   A number - Number - required
    number2:   A number - Number - required
admin
math hypot 4456 234
mentdb
4462.139845410496
Hypotenuse of the triangle 3-4-5
admin
math hypot 3 4
mentdb
5
No overflow for large values
admin
math hypot 1e200 1e200
mentdb
1.414213562373095E200
Modulus of an impedance R = 100, X = 31.4
admin
math hypot 100 31.4
mentdb
104.81393037187375
Used in use cases (19 recipes)

    Math teacher & student › Solve a right triangle and its six trig ratios
    Atomic & quantum physicist › A qubit state on the Bloch sphere
    Acoustics engineer › Room modes and degenerate frequencies of a listening room
    Crystallographer & materials physicist › Twinning in titanium: the 10-12 twin
    Chemist › Lattice parameter, X-ray density and crystallite size from XRD
    Materials scientist › Principal stresses and safety factors (Mohr circle)
    and 13 more in the Use cases
Often used with

    math atan2  ·  math rad_to_deg  ·  math sin  ·  math atan  ·  math cos  ·  math deg_to_rad  ·  math sec  ·  math sqrt

math lngamma <number>


Description

    Get the natural logarithm of the Gamma function (x > 0)

Parameters

    number:   A number - Number - required
admin
math lngamma 100
mentdb
359.1342053695754
ln(1000!) without overflow
admin
math lngamma 1001
mentdb
5912.128178488163
ln(gamma(5)) = ln(24)
admin
math lngamma 5
mentdb
3.1780538303479458
Combinations C(1000, 500) in logarithm
admin
math eval "lgamma(1001)-2*lgamma(501)"
mentdb
689.467261567851
Used in use cases (6 recipes)

    Mathematician › Gamma and Beta: classic identities checked numerically
    Cryptographer & number theorist › Key space and unicity distance of classical ciphers
    Chemist › Isotope pattern of a tetrachloro compound in MS
    Epidemiologist › Occupational cohort: SMR with exact Poisson test
    Statistician & biostatistician › The Student t density from the Gamma and Beta functions
    Actuary & risk analyst › Poisson fit of the claim counts
Often used with

    math gamma  ·  math exp  ·  math beta  ·  math log  ·  math power  ·  math round_sig  ·  constant math_pi  ·  json doc

math log <number>


Description

    Get the natural logarithm of the argument

Parameters

    number:   A number - Number - required
admin
math log 42
mentdb
3.7376696182833684
Natural logarithm: log(e) = 1
admin
math log 2.718281828459045
mentdb
1
log(1) = 0
admin
math log 1
mentdb
0
Negative number: NaN
admin
math log -1
mentdb
NaN
0: -infinity
admin
math log 0
mentdb
-Infinity
Half-life from a rate constant k = 0.1 per s
admin
math eval "ln(2)/0.1"
mentdb
6.931471805599452
Used in use cases (26 recipes)

    Mathematician › Machine epsilon and catastrophic cancellation
    Thermodynamics & heat transfer › Counterflow exchanger: effectiveness-NTU checked by LMTD
    Nuclear & radiation physicist › HPGe gamma peak: resolution, ROI and detection limit
    Advanced physical chemist › Activation enthalpy and entropy by the Eyring equation
    Pharmacist & pharmacokinetics › Pharmacokinetics: absorption, elimination and volume from the plasma concentrations
    Biologist & microbiologist › Resting membrane potential: Nernst and Goldman
    and 20 more in the Use cases
Often used with

    math exp  ·  math sqrt  ·  math expm1  ·  math power  ·  math round_sig  ·  math abs  ·  math log1p  ·  stat dist_inv

math log10 <number>


Description

    Get the base 10 logarithm of the argument

Parameters

    number:   A number - Number - required
admin
math log10 42
mentdb
1.6232492903979006
log10(1000) = 3
admin
math log10 1000
mentdb
3
Decibels: 10 log10(P2/P1) for a power ratio of 2
admin
math log10 2
mentdb
0.3010299956639812
pH of a solution [H+] = 3.2e-5 mol/L
admin
math eval "-log10(3.2e-5)"
mentdb
4.494850021680094
Sound level of 1e-5 W/m2 in dB
admin
math eval "10*log10(1e-5/1e-12)"
mentdb
70
Number of digits of 123456: floor(log10) + 1
admin
math eval "floor(log10(123456))+1"
mentdb
6
Used in use cases (11 recipes)

    Materials scientist › Hall-Petch law from ASTM grain size numbers
    Geneticist & bioinformatician › Somatic variant call: beta-binomial noise model
    Medical physicist › Linac bunker: primary barrier thickness (NCRP 147)
    Geologist & seismologist › b-value of an earthquake catalogue
    Telecom & radar engineer › QPSK receiver sensitivity from a target BER
    Electronics & signal engineer › First-order digital low-pass by the bilinear transform with prewarping
    and 5 more in the Use cases
Often used with

    math round_sig  ·  math power  ·  complex abs  ·  complex add  ·  complex div  ·  complex mul  ·  json doc  ·  json iarray

math log1p <number>


Description

    Returns the natural logarithm of the sum of the argument and 1

Parameters

    number:   A number - Number - required
admin
math log1p 42
mentdb
3.7612001156935624
Small x: ln(1+x) without cancellation
admin
math log1p 1e-12
mentdb
9.999999999995E-13
log1p(0) = 0
admin
math log1p 0
mentdb
0
Interest of 0.01 %: ln(1.0001)
admin
math log1p 0.0001
mentdb
9.999500033330834E-5
-1: -infinity
admin
math log1p -1
mentdb
-Infinity
Used in use cases (15 recipes)

    Mathematician › Machine epsilon and catastrophic cancellation
    Thermodynamics & heat transfer › Counterflow exchanger: effectiveness-NTU checked by LMTD
    Acoustics engineer › Sabine against Eyring in a dead recording booth
    Metrologist › Floating-point resolution of time stamps and frequency offsets
    Corrosion researcher › Deepest pit on a pipe by Gumbel extreme values
    Materials scientist › Recrystallization kinetics: JMAK (Avrami) law
    and 9 more in the Use cases
Often used with

    math expm1  ·  math power  ·  math log  ·  math round_sig  ·  math exp  ·  math sqrt  ·  math tanh  ·  math ulp

math log_base <number> <base>


Description

    Get the logarithm of a number in a specific base

Parameters

    number:   A number - Number - required
    base:   The base - Number - required
admin
math log_base 1000 10
mentdb
3
log2(1024) = 10
admin
math log_base 1024 2
mentdb
10
Logarithm in base 3
admin
math log_base 81 3
mentdb
4
Bits for 1000 values: log2(1000)
admin
math log_base 1000 2
mentdb
9.965784284662087
Base 10
admin
math log_base 0.001 10
mentdb
-3
Number of halvings to go from 1 to 1/1000
admin
math eval "log_base(1000, 2)"
mentdb
9.965784284662087
Used in use cases (3 recipes)

    Data validation developer › Password policy with an entropy estimate
    Algorithms in MQL › Binary search against a linear scan
    Corrosion researcher › Pourbaix diagram of iron in water
Often used with

    and  ·  arith iquo  ·  atom find  ·  atom get  ·  atom size  ·  break  ·  case  ·  is empty

math max <number1> <number2>


Description

    Returns the greater of the two numbers sent as parameters.

Parameters

    number1:   A number - Number - required
    number2:   A number - Number - required
admin
math max 4456 234
mentdb
4456
Max of two negative numbers
admin
math max -3 -7
mentdb
-3
Mixed signs
admin
math max -1.5 0
mentdb
0
Nested: the maximum of 3 values
admin
math max 4 (math max 9 2)
mentdb
9
Used in use cases (16 recipes)

    Algorithms in MQL › Stack and queue with atom lists
    Pharmacist & pharmacokinetics › Content uniformity: acceptance value and z-test
    Renewable energy engineer › Size a counterflow heat exchanger with the effectiveness-NTU method
    Robotics engineer › Joint trajectory through via points with speed limits
    Industrial quality engineer › c chart of paint defects per car body
    Deep learning engineer › Xavier initialisation of a dense layer
    and 10 more in the Use cases
Often used with

    math min  ·  and  ·  json parse_array  ·  math abs  ·  math sqrt  ·  atom get  ·  math ceil  ·  metric current available mem

math min <number1> <number2>


Description

    Returns the smaller of the numbers sent as parameters.

Parameters

    number1:   A number - Number - required
    number2:   A number - Number - required
admin
math min 4456 234
mentdb
234
Min of two decimals
admin
math min 2.5 2.49
mentdb
2.49
Negative numbers
admin
math min -3 -7
mentdb
-7
Clamp a value to 100
admin
math min 137 100
mentdb
100
Used in use cases (13 recipes)

    Algorithms in MQL › Stack and queue with atom lists
    Control flow › Paginate a REST export with for
    Pharmacist & pharmacokinetics › Carboplatin dose with the Calvert formula
    Renewable energy engineer › Size a counterflow heat exchanger with the effectiveness-NTU method
    Industrial quality engineer › Parts per million out of tolerance with the error function
    Data scientist › Market basket analysis with association rules
    and 7 more in the Use cases
Often used with

    math max  ·  math ceil  ·  math trunc  ·  json parse_array  ·  math power  ·  not  ·  string length  ·  string substr

math mod <number1> <number2>


Description

    Returns the modulo of the two numbers sent as parameters.

Parameters

    number1:   A number - Number - required
    number2:   A number - Number - required
admin
math mod 4456 234
mentdb
10
Remainder of a negative number (sign of the dividend)
admin
math mod -7 3
mentdb
-1
Even or odd
admin
math mod 17 2
mentdb
1
Hours on a 24 h clock: 30 h -> 6 h
admin
math mod 30 24
mentdb
6
Multiple of 3?
admin
math mod 123456 3
mentdb
0
Used in use cases (16 recipes)

    MQL developer › Catalogue of math and physics constants with eval
    Backend & web service developer › An authentication guard shared with include
    Date & time developer › French public holidays and a delivery date in working days
    Data validation developer › French company VAT number and social security key
    Algorithms in MQL › Euclid's GCD, fractions and exact decimals
    Deep learning engineer › A neural network learns the XOR truth table
    and 10 more in the Use cases
Often used with

    json doc  ·  json iarray  ·  string trim  ·  atom get  ·  and  ·  atom size  ·  case  ·  not

math nroot <number> <n>


Description

    Get the real n-th root (a negative number has a real root for an odd n; negative n: 1/root)

Parameters

    number:   A number - Number - required
    n:   A non zero integer - Number - required
admin
math nroot -27 3
mentdb
-3
Fifth root of 32
admin
math nroot 32 5
mentdb
2
Error: even root of a negative number
admin
math nroot -16 4
mentdb
Sorry, an error appears (a negative number has no real root of even order).
Fourth root of 81
admin
math nroot 81 4
mentdb
3
Average growth factor per year over 5 years from 100 to 150
admin
math nroot 1.5 5
mentdb
1.0844717711976986
Used in use cases (8 recipes)

    Math teacher & student › Arithmetic, geometric and harmonic means
    Crystallographer & materials physicist › X-ray crystal density and the Avogadro constant
    Electrochemist & battery engineer › Electrons transferred in the oxygen reduction (Koutecky-Levich)
    Materials scientist › Hall-Petch law from ASTM grain size numbers
    Biologist & microbiologist › Kleiber's law: allometry of the metabolic rate
    Climate & environment scientist › Planck feedback and climate sensitivity
    and 2 more in the Use cases
Often used with

    math power  ·  math cbrt  ·  math avg  ·  stat fit_model  ·  stat geo_mean  ·  stat harm_mean  ·  string regexp_extract  ·  const get

math order_int <jsonArray>


Description

    Return an ordered array of integers

Parameters

    jsonArray:   A JSON array - String - required
admin
math order_int "[8, 6, 5]"
mentdb
"[5, 6, 8]"
Negative numbers
admin
math order_int "[3, -1, 0, -5, 2]"
mentdb
[-5,-1,0,2,3]
Duplicates are kept
admin
math order_int "[4, 1, 4, 2, 1]"
mentdb
[1,1,2,4,4]
Used in use cases (7 recipes)

    MQL developer › Sort CSV columns: text sort versus numeric sorts
    Mathematician › Winning move in the game of Nim
    Industrial quality engineer › c chart of paint defects per car body
    Accountant & manager › Gaps and duplicates in the invoice numbering
    HR & payroll › Bradford factor of short absences
    Web & API developer › srcset widths of a responsive image
    and 1 more in the Use cases
Often used with

    json doc  ·  json iarray  ·  string regexp_replace  ·  json parse_array  ·  stat mode  ·  string trim  ·  json parse_obj  ·  math trunc

math order_long <jsonArray>


Description

    Return an ordered array of longs

Parameters

    jsonArray:   A JSON array - String - required
admin
math order_long "[8, 6, 5]"
mentdb
"[5, 6, 8]"
Large integers
admin
math order_long "[9000000000, 12, 7000000000]"
mentdb
[12,7000000000,9000000000]
Negative numbers
admin
math order_long "[5, -2, 0]"
mentdb
[-2,0,5]
Used in use cases (3 recipes)

    MQL developer › Sort CSV columns: text sort versus numeric sorts
    Data quality analyst › Gaps and duplicates in an invoice number sequence
    Web & API developer › Resolve npm semver ranges
Often used with

    and  ·  atom before_includ  ·  atom distinct  ·  atom get  ·  atom size  ·  date long_to_ts  ·  json doc  ·  json iarray

math order_double <jsonArray>


Description

    Return an ordered array of doubles

Parameters

    jsonArray:   A JSON array - String - required
admin
math order_double "[8, 6, 5]"
mentdb
"[5, 6, 8]"
Sort decimals
admin
math order_double "[3.2, -1.5, 2.25, 0]"
mentdb
[-1.5,0.0,2.25,3.2]
Scientific notation
admin
math order_double "[1e-3, 5e-4, 2e-2]"
mentdb
[5.0E-4,0.001,0.02]
Measures of a sample
admin
math order_double "[12.1, 11.4, 13.2, 10.9, 12.8]"
mentdb
[10.9,11.4,12.1,12.8,13.2]
Used in use cases (9 recipes)

    MQL developer › Sort CSV columns: text sort versus numeric sorts
    Math teacher & student › A class test: mode, frequency table, two variances
    Optics & photonics › Diffraction grating: orders and angles of a spectrum
    Acoustics engineer › Room modes and degenerate frequencies of a listening room
    Chemist › Method bias on a certified reference material
    Medical physicist › Proton therapy: energy layers with the Bragg-Kleeman rule
    and 3 more in the Use cases
Often used with

    math avg  ·  stat mode  ·  json doc  ·  json iarray  ·  stat mean  ·  stat ztest  ·  string replace  ·  atom distinct

math order_float <jsonArray>


Description

    Return an ordered array of floats

Parameters

    jsonArray:   A JSON array - String - required
admin
math order_float "[8, 6, 5]"
mentdb
"[5, 6, 8]"
Decimal numbers
admin
math order_float "[2.5, -1.25, 0.5]"
mentdb
[-1.25,0.5,2.5]
Already sorted
admin
math order_float "[1, 2, 3]"
mentdb
[1.0,2.0,3.0]
Used in use cases (1 recipe)

    MQL developer › Sort CSV columns: text sort versus numeric sorts
Often used with

    atom distinct  ·  atom size  ·  date long_to_ts  ·  math order_double  ·  math order_int  ·  math order_long  ·  stat mode  ·  string order

math percent <number> <p>


Description

    Get p percent of x: x*p/100 (computed in decimal)

Parameters

    number:   The number x - Number - required
    p:   The percentage - Number - required
admin
math percent 80 15
mentdb
12
VAT of 8.5 % on 250
admin
math percent 250 8.5
mentdb
21.25
VAT of 20 % on 59.90
admin
math percent 59.90 20
mentdb
11.98
More than 100 %
admin
math percent 40 150
mentdb
60
Discount of 12.5 % on 240
admin
math percent 240 12.5
mentdb
30
Used in use cases (1 recipe)

    Accountant & manager › Invoice totals with two VAT rates and the due date
Often used with

    date add  ·  date add_business_days  ·  date is_weekend  ·  date last_day_of_month

math pi


Description

    Get the value of pi

admin
math pi
mentdb
3.141592653589793
Area of a disk of radius 2
admin
math calc "pi*2^2"
mentdb
12.566370614359172
Circumference of a circle of radius 3
admin
math eval "2*pi*3"
mentdb
18.84955592153876
Area of a disc of diameter 10 cm, in cm2
admin
math eval "pi*5^2"
mentdb
78.53981633974483
More digits with bigdec pi
admin
bigdec pi 30
mentdb
3.14159265358979323846264338328
Used in use cases (7 recipes)

    Physicist › Period of a pendulum at large amplitude
    Control engineer › Time-domain specs from the closed-loop poles
    Electronics & signal engineer › First-order digital low-pass by the bilinear transform with prewarping
    Statistician & biostatistician › The Student t density from the Gamma and Beta functions
    Control engineer › Continuous poles of an identified discrete model
    Control engineer › Relay autotuning of a temperature loop
    and 1 more in the Use cases
Often used with

    math sqrt  ·  complex abs  ·  complex div  ·  complex im  ·  complex re  ·  math exp  ·  num poly_roots  ·  complex add

math pow <number1> <number2>


Description

    Returns 'number1' raised to the power of 'number2'.

Parameters

    number1:   A number - Number - required
    number2:   A number - Number - required
admin
math pow 0.5 7
mentdb
0.0078125
Square root as a power
admin
math pow 2 0.5
mentdb
1.4142135623730951
Negative exponent
admin
math pow 10 -3
mentdb
0.001
Negative base, integer exponent
admin
math pow -2 3
mentdb
-8
Negative base, decimal exponent: NaN (use math calc for the complex value)
admin
math pow -8 0.3333333333333333
mentdb
NaN
0^0 = 1
admin
math pow 0 0
mentdb
1
Fourth power of an amplitude
admin
math pow 1.5 4
mentdb
5.0625
Used in use cases (5 recipes)

    Execution modes › Run the generated execute, call and include
    Algorithms in MQL › Matrix product: triple loop against matrix mul
    Mathematical physicist › Tight-binding chain and Chebyshev polynomials
    Biologist & microbiologist › qPCR: efficiency from the standard curve and relative expression
    Excel reporting analyst › Investment appraisal: NPV, IRR and discounted payback
Often used with

    matrix norm_frobenius  ·  matrix trace  ·  string replace  ·  date current_ms  ·  eval  ·  excelx cell eval  ·  excelx cell ref  ·  excelx cell set

math power <number1> <number2>


Description

    Returns 'number1' raised to the power of 'number2'.

Parameters

    number1:   A number - Number - required
    number2:   A number - Number - required
admin
math power 0.5 7
mentdb
0.0078125
Same as math pow
admin
math power 2 10
mentdb
1024
Square root as a power
admin
math power 9 0.5
mentdb
3
Large result
admin
math power 10 300
mentdb
1.0E300
Overflow: infinity
admin
math power 10 400
mentdb
Infinity
Used in use cases (47 recipes)

    MQL developer › User rights as a bitmask
    Math teacher & student › Simplify an expression, then solve with roots
    Optics & photonics › Fabry-Perot etalon: FSR, finesse and linewidth
    Thermodynamics & heat transfer › Radiation and convection loss of a steam pipe
    Nuclear & radiation physicist › Is the background really Poisson?
    Mathematical physicist › Volume of the n-ball with Gamma and Beta
    and 41 more in the Use cases
Often used with

    math sqrt  ·  math gamma  ·  math log  ·  json parse_array  ·  math exp  ·  math log1p  ·  stat fit_model  ·  stat mean

math rad_to_deg <number>


Description

    Converts an angle measured in radians to an approximately equivalent angle measured in degrees

Parameters

    number:   A number - Number - required
admin
math rad_to_deg 42
mentdb
2406.4227395494577
pi radians = 180 degrees
admin
math rad_to_deg 3.141592653589793
mentdb
180
1 radian in degrees
admin
math rad_to_deg 1
mentdb
57.29577951308232
pi/6
admin
math rad_to_deg 0.5235987755982988
mentdb
29.999999999999996
Negative angle
admin
math rad_to_deg -1.5707963267948966
mentdb
-90
Used in use cases (30 recipes)

    Mathematician › Cube roots of a complex number
    Math teacher & student › Solve a right triangle and its six trig ratios
    Physicist › Total internal reflection and the evanescent wave
    Optics & photonics › Fresnel reflectance and the Brewster angle
    Atomic & quantum physicist › A qubit state on the Bloch sphere
    Crystallographer & materials physicist › Symmetry operations: rotation angle, order and the crystallographic restriction
    and 24 more in the Use cases
Often used with

    math deg_to_rad  ·  math atan2  ·  complex add  ·  complex abs  ·  math hypot  ·  complex arg  ·  complex div  ·  complex mul

math random <number>


Description

    Get a random number between 0 and the given argument 'number'.

Parameters

    number:   A number - Number - required
admin
math random 42
mentdb
1
A random integer between 0 and 5 (dice - 1)
admin
math random 6
mentdb
0
Random integer between 0 and 99 (the result changes each time)
admin
math floor (math random 100)
mentdb
81

math rint <number>


Description

    Returns the double value that is closest to the argument and is equal to a mathematical integer

Parameters

    number:   A number - Number - required
admin
math rint 42
mentdb
42
Half to even: 2.5 -> 2
admin
math rint 2.5
mentdb
2
3.5 -> 4
admin
math rint 3.5
mentdb
4
Banker rounding: 0.5 goes to the even integer
admin
math rint 0.5
mentdb
0
Negative number
admin
math rint -2.5
mentdb
-2
Not a half: normal rounding
admin
math rint 2.6
mentdb
3
Used in use cases (8 recipes)

    Math teacher & student › Rounding, truncating and the sign of negative numbers
    Acoustics engineer › Room modes and degenerate frequencies of a listening room
    Operations researcher › EOQ, safety stock and reorder point
    Advanced physical chemist › Rotational populations of HCl
    Robotics engineer › Jerk-limited point-to-point move of an axis
    Electronics & signal engineer › Quantization noise of an 8-bit ADC
    and 2 more in the Use cases
Often used with

    math frac_part  ·  math abs  ·  math ceil  ·  math sign  ·  math signum  ·  math trunc  ·  math ulp  ·  and

math round <number1> <number2>


Description

    Rounds 'number 1' to the precision specified by 'number 2'.

Parameters

    number1:   A number - Number - required
    number2:   A number - Number - required
admin
math round 1.23654 2
mentdb
1.24
Round to 0 decimal
admin
math round 2.5 0
mentdb
3
Round to 3 decimals
admin
math round 3.14159265 3
mentdb
3.142
Round to 1 decimal
admin
math round 9.8066 1
mentdb
9.8
No decimal
admin
math round 1234.5678 0
mentdb
1235
Negative number
admin
math round -2.675 2
mentdb
-2.67
Used in use cases (641 recipes)

    MQL beginner › Savings plan: while, repeat, break and continue
    Backend & web service developer › Publish a typed web service with its parameter and stack options
    Date & time developer › Run log header and execution timer
    String & encoding developer › Mail merge: fill a template from JSON data
    Data validation developer › Password policy with an entropy estimate
    Script developer › A script with typed parameters rejects bad calls
    and 635 more in the Use cases
Often used with

    math sqrt  ·  math round_sig  ·  unit convert  ·  stat mean  ·  num solve  ·  json doc  ·  json load select  ·  math power

math round_sig <number> <digits>


Description

    Round a number to n significant figures (the significant zeros are kept: 2.0001 with 3 figures gives 2.00). The rounding is done on the decimal value (HALF_UP).

Parameters

    number:   A number - Number - required
    digits:   The number of significant figures (1 to 100) - Number - required
admin
math round_sig 0.0123456 3
mentdb
0.0123
admin
math round_sig 2.0001 3
mentdb
2.00
3 significant digits of a large number
admin
math round_sig 299792458 3
mentdb
300000000
2 significant digits
admin
math round_sig 0.000123456 2
mentdb
0.00012
Avogadro number with 4 significant digits
admin
math round_sig 6.02214076e23 4
mentdb
602200000000000000000000
1 significant digit
admin
math round_sig 0.0456 1
mentdb
0.05
Negative number
admin
math round_sig -123.456 2
mentdb
-120
Used in use cases (60 recipes)

    Mathematician › Spectrum and invariants of a symmetric matrix
    Physicist › Relativistic velocity addition with rapidities
    Optics & photonics › Step-index fiber: critical angle, NA and V number
    Nuclear & radiation physicist › Binding energy of the deuteron from the masses
    Atomic & quantum physicist › Rydberg constant from alpha and me, with uncertainty
    Cryptographer & number theorist › Password entropy, brute-force time and bcrypt
    and 54 more in the Use cases
Often used with

    json load select  ·  string regexp_extract  ·  stat mean  ·  const get  ·  math exp  ·  math sqrt  ·  stat dist_inv  ·  unit convert

math round_uncertainty <value> <uncertainty>


Description

    Write a measurement as "value ± uncertainty" with the usual rounding (Particle Data Group rule): the 3 first digits of the uncertainty give 2 significant figures (100 to 354), 1 significant figure (355 to 949), or 2 after rounding up (950 to 999); the value is rounded at the same decimal place.
The very big and very small numbers are written with a common power of ten: (1.235 ± 0.034)e-8

Parameters

    value:   The value - Number - required
    uncertainty:   The uncertainty (strictly positive) - Number - required
admin
math round_uncertainty 9.81234 0.0456
mentdb
9.81 ± 0.05
admin
math round_uncertainty 1.23456 0.012
mentdb
1.235 ± 0.012
Uncertainty with 2 digits when it starts with 1
admin
math round_uncertainty 1.23456 0.0123
mentdb
1.235 ± 0.012
A large value
admin
math round_uncertainty 299792.458 12.3
mentdb
299792 ± 12
Uncertainty with a leading 1: 2 digits are kept
admin
math round_uncertainty 12.3456 0.0156
mentdb
12.346 ± 0.016
Large uncertainty
admin
math round_uncertainty 1234.5 87
mentdb
1230 ± 90
Result of a fit: tau = 1.954461 +- 0.076915
admin
math round_uncertainty 1.954461 0.076915
mentdb
1.95 ± 0.08
Used in use cases (7 recipes)

    Thermodynamics & heat transfer › Newton's law of cooling: fit, then predict
    Nuclear & radiation physicist › Measure a half-life from counts
    Advanced physical chemist › Activation energy from rate constants
    Corrosion researcher › Corrosion rate from coupon mass loss (ASTM G1/G31)
    Biologist & microbiologist › Enzyme kinetics: Km, kcat and catalytic efficiency
    IoT & sensor engineer › Temperature uncertainty of a PT100 probe
    and 1 more in the Use cases
Often used with

    stat fit_model  ·  unit calc  ·  num ode  ·  num uncertainty  ·  stat conf_interval_mean

math sec <number>


Description

    Get the secant (1/cos) of a number

Parameters

    number:   A number - Number - required
admin
math sec 0
mentdb
1
sec(pi/3) = 2
admin
math sec 1.0471975511965979
mentdb
2.0000000000000004
sec(pi/4) = sqrt(2)
admin
math sec 0.7853981633974483
mentdb
1.414213562373095
sec(pi) = -1
admin
math sec 3.141592653589793
mentdb
-1
Used in use cases (6 recipes)

    Math teacher & student › Solve a right triangle and its six trig ratios
    Crystallographer & materials physicist › Crystallite size and microstrain: Williamson-Hall plot
    Chemist › Lattice parameter, X-ray density and crystallite size from XRD
    Astronomer › Altitude, azimuth and air mass of Betelgeuse
    Aeronautical engineer › Load factor, radius and rate of a level turn
    Mechanical & civil engineer › Member forces of a triangular roof truss by the method of joints
Often used with

    math tan  ·  math atan2  ·  math hypot  ·  math rad_to_deg  ·  math sin  ·  math atan  ·  math cot  ·  math csc

math sign <number>


Description

    Get the sign of a number

Parameters

    number:   A number - Number - required
admin
math sign 42
mentdb
1
Sign of a negative number
admin
math sign -0.001
mentdb
-1
Sign of 0
admin
math sign 0
mentdb
0
Negative number
admin
math sign -12.5
mentdb
-1
Very small positive number
admin
math sign 1e-300
mentdb
1
Used in use cases (7 recipes)

    MQL beginner › Split a bill: functions inside functions
    Math teacher & student › Rounding, truncating and the sign of negative numbers
    Process & reactor engineer › Mass balance of a two-column distillation train
    Meteorologist › Static stability of a sounding layer
    Data quality analyst › Placeholder values and debit/credit sign consistency
    Accountant & manager › Cash rounding of tickets to 5 cents
    and 1 more in the Use cases
Often used with

    math frac_part  ·  math signum  ·  math rint  ·  math trunc  ·  atom get  ·  atom size  ·  bd*  ·  bd+

math signum <number>


Description

    Get the sign of a number: returns 1 if the number is positive and -1 if the number is negative.

Parameters

    number:   A number - Number - required
admin
math signum 42
mentdb
1
Same as math sign
admin
math signum -42
mentdb
-1
Zero
admin
math signum 0
mentdb
0
Decimal number
admin
math signum 0.25
mentdb
1
Used in use cases (8 recipes)

    Math teacher & student › Rounding, truncating and the sign of negative numbers
    Crystallographer & materials physicist › Twinning in titanium: the 10-12 twin
    Corrosion researcher › Galvanic couple steel-copper: Evans mixed potential
    Biologist & microbiologist › Resting membrane potential: Nernst and Goldman
    Meteorologist › Static stability of a sounding layer
    Robotics engineer › Re-orthonormalize a drifting rotation matrix with QR
    and 2 more in the Use cases
Often used with

    math sign  ·  math frac_part  ·  math rint  ·  math round_sig  ·  unit convert  ·  constant physics_f  ·  json parse_array  ·  math abs

math sin <number>


Description

    Get the sine of a number

Parameters

    number:   A number - Number - required
admin
math sin 42
mentdb
-0.9165215479156338
sin(pi/6) = 0.5
admin
math sin 0.5235987755982988
mentdb
0.49999999999999994
The angle is in radians: 30 degrees
admin
math sin (math deg_to_rad 30)
mentdb
0.49999999999999994
sin(pi) = 0 (almost: rounding of pi)
admin
math sin 3.141592653589793
mentdb
1.2246467991473532E-16
Height of a ramp of 5 m at 12 degrees
admin
math eval "5*sin(12)" "{\"_angle\": \"deg\"}"
mentdb
1.0395584540887968
sin(-x) = -sin(x)
admin
math sin -1
mentdb
-0.8414709848078965
Small x: sin(x) = x
admin
math sin 1e-8
mentdb
1.0E-8
Used in use cases (15 recipes)

    Math teacher & student › Solve a right triangle and its six trig ratios
    Optics & photonics › Fresnel reflectance and the Brewster angle
    Crystallographer & materials physicist › Crystallite size and microstrain: Williamson-Hall plot
    Chemist › Lattice parameter, X-ray density and crystallite size from XRD
    Medical physicist › HDR brachytherapy: TG-43 line-source dose rate
    Agronomist › Field slope, aspect and USLE LS factor from a DEM
    and 9 more in the Use cases
Often used with

    math cos  ·  math atan2  ·  math hypot  ·  matrix get  ·  math atan  ·  math rad_to_deg  ·  math tan  ·  math asin

math sinh <number>


Description

    Get the hyperbolic sine of a number

Parameters

    number:   A number - Number - required
admin
math sinh 42
mentdb
8.696374707602505E17
sinh(1)
admin
math sinh 1
mentdb
1.1752011936438014
sinh(0) = 0
admin
math sinh 0
mentdb
0
Odd function
admin
math sinh -1
mentdb
-1.1752011936438014
Large x: overflow to infinity
admin
math sinh 1000
mentdb
Infinity
Used in use cases (8 recipes)

    Mathematician › Hyperbolic functions and the Gudermannian
    Physicist › Relativistic velocity addition with rapidities
    Atomic & quantum physicist › Electron tunnelling through a rectangular barrier
    Mathematical physicist › Rapidity, Lorentz factor and pseudorapidity
    Advanced physical chemist › Heat capacity of diamond: Einstein vs Debye
    Space mission engineer › Hyperbolic departure orbit to Mars
    and 2 more in the Use cases
Often used with

    math tanh  ·  math acosh  ·  math cosh  ·  math atanh  ·  constant physics_c  ·  constant physics_e  ·  math asinh  ·  math atan

math sqrt <number>


Description

    Get the square root of a non-negative number

Parameters

    number:   A number - Number - required
admin
math sqrt 42
mentdb
6.48074069840786
sqrt(2)
admin
math sqrt 2
mentdb
1.4142135623730951
Negative number: NaN (use complex sqrt)
admin
math sqrt -4
mentdb
NaN
Perfect square
admin
math sqrt 144
mentdb
12
Standard deviation from a variance of 6.25
admin
math sqrt 6.25
mentdb
2.5
Very small number
admin
math sqrt 1e-20
mentdb
1.0E-10
Used in use cases (56 recipes)

    Physicist › Skydiver with quadratic drag: tanh and acosh
    Optics & photonics › Measuring a Gaussian beam with a knife edge
    Thermodynamics & heat transfer › Aluminium pin fin: heat rate, efficiency, tip temperature
    Nuclear & radiation physicist › HPGe gamma peak: resolution, ROI and detection limit
    Atomic & quantum physicist › Electron tunnelling through a rectangular barrier
    Cryptographer & number theorist › Timing side channel of a password check
    and 50 more in the Use cases
Often used with

    math erf_inv  ·  math erfc  ·  math exp  ·  stat mean  ·  math abs  ·  math power  ·  stat ztest  ·  stat pvariance

math tan <number>


Description

    Get the tangent of a number

Parameters

    number:   A number - Number - required
admin
math tan 42
mentdb
2.2913879924374863
tan(pi/4) = 1
admin
math tan 0.7853981633974483
mentdb
0.9999999999999999
tan(0) = 0
admin
math tan 0
mentdb
0
Height of a tree seen at 35 degrees from 20 m
admin
math eval "20*tan(35)" "{\"_angle\": \"deg\"}"
mentdb
14.004150764194193
Near pi/2: very large
admin
math tan 1.5707963267948966
mentdb
1.633123935319537E16
Used in use cases (12 recipes)

    Math teacher & student › Solve a right triangle and its six trig ratios
    Optics & photonics › Fresnel reflectance and the Brewster angle
    Mathematical physicist › Rapidity, Lorentz factor and pseudorapidity
    Crystallographer & materials physicist › Crystallite size and microstrain: Williamson-Hall plot
    Agronomist › Field slope, aspect and USLE LS factor from a DEM
    Astronomer › Sunrise, sunset and equation of time at the winter solstice
    and 6 more in the Use cases
Often used with

    math atan  ·  math rad_to_deg  ·  math cot  ·  math deg_to_rad  ·  math sec  ·  math sin  ·  complex abs  ·  math atan2

math tanh <number>


Description

    Get the hyperbolic tangent of a number

Parameters

    number:   A number - Number - required
admin
math tanh 42
mentdb
1
tanh(1)
admin
math tanh 1
mentdb
0.7615941559557649
Large x: 1
admin
math tanh 20
mentdb
1
tanh(0) = 0
admin
math tanh 0
mentdb
0
Odd function
admin
math tanh -0.5
mentdb
-0.46211715726000974
Used in use cases (12 recipes)

    Mathematician › Hyperbolic functions and the Gudermannian
    Physicist › Relativistic velocity addition with rapidities
    Thermodynamics & heat transfer › Aluminium pin fin: heat rate, efficiency, tip temperature
    Nuclear & radiation physicist › Cosmic muons: time dilation in numbers
    Mathematical physicist › Rapidity, Lorentz factor and pseudorapidity
    Biologist & microbiologist › Photosynthesis-irradiance curve (Jassby-Platt)
    and 6 more in the Use cases
Often used with

    math acosh  ·  math atanh  ·  math cosh  ·  math sinh  ·  string regexp_extract  ·  math exp  ·  math sqrt  ·  unit convert

math trunc <number>


Description

    Get the integer part toward 0 (trunc -2.7 = -2)

Parameters

    number:   A number - Number - required
admin
math trunc -2.7
mentdb
-2
Integer part of a positive number
admin
math trunc 2.7
mentdb
2
An integer is unchanged
admin
math trunc 7
mentdb
7
Small negative number: -0 is 0
admin
math trunc -0.4
mentdb
0
Integer part of a duration of 3.75 h
admin
math trunc 3.75
mentdb
3
Used in use cases (22 recipes)

    MQL beginner › Split a bill: functions inside functions
    Date & time developer › French public holidays and a delivery date in working days
    String & encoding developer › Mail merge: fill a template from JSON data
    Mathematician › Winning move in the game of Nim
    Math teacher & student › Rounding, truncating and the sign of negative numbers
    Optics & photonics › Diffraction grating: orders and angles of a spectrum
    and 16 more in the Use cases
Often used with

    math frac_part  ·  math bit_and  ·  math ceil  ·  string lpad  ·  json parse_array  ·  math bit_or  ·  math bit_xor  ·  string trim

math ulp <number>


Description

    Returns the size of an ulp of the argument. An ulp of a double value is the positive distance between this floating-point value and the next larger double value in magnitude

Parameters

    number:   A number - Number - required
admin
math ulp 42
mentdb
7.105427357601002E-15
Spacing of the doubles near 1 (machine epsilon)
admin
math ulp 1
mentdb
2.220446049250313E-16
Precision of a double near 1e10
admin
math ulp 1e10
mentdb
1.9073486328125E-6
Near 0
admin
math ulp 1e-300
mentdb
1.6578092E-316
Relative precision of the doubles: ulp(1)/2
admin
math eval "2^-53"
mentdb
1.1102230246251565E-16
Used in use cases (4 recipes)

    Mathematician › Machine epsilon and catastrophic cancellation
    Metrologist › Floating-point resolution of time stamps and frequency offsets
    Electronics & signal engineer › Quantization noise of an 8-bit ADC
    Data quality analyst › Sub-cent amounts, truncation and floating point noise
Often used with

    math expm1  ·  math frac_part  ·  math log1p  ·  math rint  ·  math round_sig  ·  json doc  ·  json iarray  ·  math abs

math to_words <n> <lang>


Description

    An integer in words, in French (1990 rules, hyphens) or in English

Parameters

    n:   The integer - Number - required
    lang:   fr or en - String - required
admin
math to_words 1980 "fr"
mentdb
mille-neuf-cent-quatre-vingts
admin
math to_words 71 "fr"
mentdb
soixante-et-onze
admin
math to_words 1980 "en"
mentdb
one thousand nine hundred eighty

math amount_in_words <amount> <lang> <currency>


Description

    An amount in words with its currency (EUR, USD, GBP, CHF...), for invoices and cheques

Parameters

    amount:   The amount - Number - required
    lang:   fr or en - String - required
    currency:   EUR, USD, GBP, CHF... - String - required
admin
math amount_in_words 1234.56 "fr" "EUR"
mentdb
mille-deux-cent-trente-quatre euros et cinquante-six centimes
admin
math amount_in_words 2000000 "fr" "EUR"
mentdb
deux-millions d'euros
admin
math amount_in_words 81.01 "en" "USD"
mentdb
eighty-one dollars and one cent
Used in use cases (1 recipe)

    Accountant & manager › Invoice total, VAT, amount in words and due date
Often used with

    date add_business_days_fr  ·  math vat  ·  table window

math roman <n>


Description

    An integer (1 to 3999) in roman numerals

Parameters

    n:   The integer - Number - required
admin
math roman 2026
mentdb
MMXXVI

math from_roman <roman>


Description

    A roman numeral as an integer

Parameters

    roman:   The roman numeral - String - required
admin
math from_roman "MCMXCIV"
mentdb
1994

math round_bank <x> <decimals>


Description

    Banker's rounding (half to even, IEEE 754): 2.5 -> 2, 3.5 -> 4; no bias when many values are rounded

Parameters

    x:   The number - Number - required
    decimals:   The number of decimals - Number - required
admin
math round_bank 2.5 0
mentdb
2
admin
math round_bank 2.675 2
mentdb
2.68

math vat <amount> <rate> <from>


Description

    Price excluding tax, VAT and price including tax from one of them and the rate in %, rounded to the cent

Parameters

    amount:   The amount - Number - required
    rate:   The rate in % - Number - required
    from:   ht (excluding tax) or ttc (including tax) - String - required
admin
math vat 100 20 "ht"
mentdb
{"ht": 100, "vat": 20, "ttc": 120, "rate": 20}
admin
math vat 59.99 8.5 "ttc"
mentdb
{"ht": 55.29, "vat": 4.7, "ttc": 59.99, "rate": 8.5}
Used in use cases (1 recipe)

    Accountant & manager › Invoice total, VAT, amount in words and due date
Often used with

    date add_business_days_fr  ·  math amount_in_words  ·  table window

math random_int <min> <max>


Description

    A secure random integer between min and max included (PHP random_int; 64-bit integers)

Parameters

    min:   The minimum - Number - required
    max:   The maximum - Number - required
admin
math random_int 1 6
mentdb
4
Complete: a dice roll is between 1 and 6
admin
-> "[d]" (math random_int 1 6); (and (>= [d] 1) (<= [d] 6))
mentdb
1