clamp function

Syntax

  • float clamp(x, min, max)
  • string clamp(x, min, max)
  • float[] clamp(x, min, max)
  • string[] clamp(x, min, max)

Parameters

  1. x—(float, string, float[], string[])
  2. min—(float, string, float[], string[])

    Must be the same type as x.

  3. max—(float, string, float[], string[])

    Must be the same type as x.

Returns

Returns min if x is less than min, max if x is greater than max, and x otherwise. For arrays, the operation is applied element-wise and an array with the pairwise clamped values is returned.

Description

The clamp function clamps x to the range [min, max].

Related

Examples

clamp(1.5, 0, 1)
# result = 1
clamp(-11, -10, 10)
# result = -10