clamp function

Syntax

  • float clamp(x, min, max)

Parameters

  1. xfloat
    The number to clamp.
  2. minfloat
    Lower bound of range to which x is clamped. Minimum value returned.
  3. maxfloat
    Upper bound of range to which x is clamped. Maximum value returned.

Returns

Returns min if x is less than min, max if x is greater than max, and x otherwise.

Description

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

Related

Examples

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

In this topic