DocsSoma NodeConstants

Built-in Constants

Numeric constants available in every Soma script without declaration. User-declared names (let, input, param) shadow these if they use the same identifier.

Mathematical Constants

NameValueDescriptionCommon use in trading
pi3.141592653589793π — ratio of circle circumference to diameter.Cycle analysis, sinusoidal curve fitting.
tau6.283185307179586τ = 2π — one full revolution in radians.Period normalisation in wave-based indicators.
e2.718281828459045Euler's number — base of the natural logarithm.Continuous compounding, log-return calculations.
phi1.618033988749895φ — the golden ratio (1 + √5) / 2.Fibonacci retracement and extension levels.
sqrt21.4142135623730951√2 — square root of 2.Diagonal geometry, volatility scaling.
ln20.6931471805599453Natural logarithm of 2.Doubling-time calculations: t = ln2 / r.
ln102.302585092994046Natural logarithm of 10.Conversion between log bases.

Sentinel Constants

Sentinel values for initialising variables to extreme or undefined states, and for testing NaN-safe logic.

NameJS valueDescription
nanNaNNot-a-number. Propagates through arithmetic — any operation with nan produces nan. Use isnan() to test, or ?? to substitute a fallback value.
infInfinityPositive infinity. Useful for initialising a "best minimum" accumulator: let best = inf.
ninf-InfinityNegative infinity. Useful for initialising a "best maximum" accumulator: let worst = ninf.

Usage examples

# Find the rolling highest close in the last 'period' bars
param period as int = 20
input prices
output highest

for (i, v) in prices {
  let best = ninf           # start below any possible value
  let j = 0
  while j < period and (i - j) >= 0 {
    let c = prices[j]       # look-back indexing
    if c > best { best = c }
    j = j + 1
  }
  highest[i] = best
}

# Guard against division by NaN
let ratio = a / (b ?? 1)    # use 1 if b is NaN

# Fibonacci retracement level
let fib618 = range_high - (range_high - range_low) * phi / (phi + 1)

Name Shadowing

If a user-declared identifier has the same name as a constant, the declaration takes precedence within its scope. Constants are resolved from the global scope at the start of execution, so a let inside a for block only shadows the constant in that block.

# "pi" is shadowed inside this loop — global pi is untouched
for (i, v) in prices {
  let pi = 3.14   # shadows the constant only within this block
  result[i] = v * pi
}

# Outside the loop, pi is still 3.141592653589793
let circumference = 2 * pi * radius