Builtins: math
| Signature | Returns |
|---|---|
| math.abs(x: float) -> float | Absolute value |
| math.min(a: float, b: float) -> float | Smaller of exactly two values |
| math.max(a: float, b: float) -> float | Larger of exactly two values |
| math.round(x: float [, digits: int]) -> float | Nearest whole number, or rounded to digits decimals, 0 through 15 |
| math.round_to_tick(x: float) -> float | Rounded to the instrument tick, nan when the chart states no tick |
| math.floor(x: float) -> float | Round down |
| math.ceil(x: float) -> float | Round up |
| math.sqrt(x: float) -> float | Square root |
| math.pow(base: float, exponent: float) -> float | Power |
| math.log(x: float) -> float | Natural logarithm |
| math.exp(x: float) -> float | Natural exponential |
| math.sign(x: float) -> float | Minus one, zero or one |
| math.clamp(x: float, low: float, high: float) -> float | x held inside your own bounds |
| math.scale(x: float, in_min: float, in_max: float, out_min: float, out_max: float) -> float | x remapped from one range to another, clamped at both ends |
| math.avg(a: float, b: float, ... ) -> float | Mean of 2 to 24 values |
| math.log10(x: float) -> float | Base 10 logarithm |
| math.sin, math.cos, math.tan(x: float) -> float | Trigonometry in radians |
| math.asin, math.acos, math.atan(x: float) -> float | The inverse functions, in radians |
| math.todegrees(x: float) -> float, math.toradians(x: float) -> float | Angle conversion |
| math.pi, math.e | The constants, written without parentheses |
math.min and math.max take exactly two arguments; nest them for more. An undefined domain, such as the square root of a negative number, returns nan.
math.log, math.log10, math.exp, math.pow and the trigonometry give the same result, to the last digit, on every device, so a script draws the same thing in the browser, in the desktop app and on the phone.
math.scale maps a size to a radius. It is clamped at both ends on purpose, so a print far above the top of your range keeps the largest radius instead of drawing a circle wider than the chart. It answers nan for a nan x, and when in_max is not above in_min it answers out_max at or above in_min and out_min below it.
let size: float = tape.largest_size()
let radius: float = math.scale(nz(size, 0), 25, 400, 5, 22)