Version: Unity 6.5 Alpha (6000.5)
LanguageEnglish
  • C#

math.clamp

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static int clamp(int valueToClamp, int lowerBound, int upperBound);

Parameters

Parameter Description
valueToClamp Input value to be clamped.
lowerBound Lower bound of the interval.
upperBound Upper bound of the interval.

Returns

int The clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].

Description

Returns the result of clamping the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are int values.


Declaration

public static int2 clamp(int2 valueToClamp, int2 lowerBound, int2 upperBound);

Parameters

Parameter Description
valueToClamp Input value to be clamped.
lowerBound Lower bound of the interval.
upperBound Upper bound of the interval.

Returns

int2 The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].

Description

Returns the result of a componentwise clamping of the int2 x into the interval [a, b], where a and b are int2 vectors.


Declaration

public static int3 clamp(int3 valueToClamp, int3 lowerBound, int3 upperBound);

Parameters

Parameter Description
valueToClamp Input value to be clamped.
lowerBound Lower bound of the interval.
upperBound Upper bound of the interval.

Returns

int3 The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].

Description

Returns the result of a componentwise clamping of the int3 x into the interval [a, b], where x, a and b are int3 vectors.


Declaration

public static int4 clamp(int4 valueToClamp, int4 lowerBound, int4 upperBound);

Parameters

Parameter Description
valueToClamp Input value to be clamped.
lowerBound Lower bound of the interval.
upperBound Upper bound of the interval.

Returns

int4 The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].

Description

Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are int4 vectors.


Declaration

public static uint clamp(uint valueToClamp, uint lowerBound, uint upperBound);

Parameters

Parameter Description
valueToClamp Input value to be clamped.
lowerBound Lower bound of the interval.
upperBound Upper bound of the interval.

Returns

uint The clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].

Description

Returns the result of clamping the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are uint values.


Declaration

public static uint2 clamp(uint2 valueToClamp, uint2 lowerBound, uint2 upperBound);

Parameters

Parameter Description
valueToClamp Input value to be clamped.
lowerBound Lower bound of the interval.
upperBound Upper bound of the interval.

Returns

uint2 The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].

Description

Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are uint2 vectors.


Declaration

public static uint3 clamp(uint3 valueToClamp, uint3 lowerBound, uint3 upperBound);

Parameters

Parameter Description
valueToClamp Input value to be clamped.
lowerBound Lower bound of the interval.
upperBound Upper bound of the interval.

Returns

uint3 The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].

Description

Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are uint3 vectors.


Declaration

public static uint4 clamp(uint4 valueToClamp, uint4 lowerBound, uint4 upperBound);

Parameters

Parameter Description
valueToClamp Input value to be clamped.
lowerBound Lower bound of the interval.
upperBound Upper bound of the interval.

Returns

uint4 The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].

Description

Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are uint4 vectors.


Declaration

public static long clamp(long valueToClamp, long lowerBound, long upperBound);

Parameters

Parameter Description
valueToClamp Input value to be clamped.
lowerBound Lower bound of the interval.
upperBound Upper bound of the interval.

Returns

long The clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].

Description

Returns the result of clamping the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are long values.


Declaration

public static ulong clamp(ulong valueToClamp, ulong lowerBound, ulong upperBound);

Parameters

Parameter Description
valueToClamp Input value to be clamped.
lowerBound Lower bound of the interval.
upperBound Upper bound of the interval.

Returns

ulong The clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].

Description

Returns the result of clamping the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are ulong values.


Declaration

public static float clamp(float valueToClamp, float lowerBound, float upperBound);

Parameters

Parameter Description
valueToClamp Input value to be clamped.
lowerBound Lower bound of the interval.
upperBound Upper bound of the interval.

Returns

float The clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].

Description

Returns the result of clamping the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are float values.


Declaration

public static float2 clamp(float2 valueToClamp, float2 lowerBound, float2 upperBound);

Parameters

Parameter Description
valueToClamp Input value to be clamped.
lowerBound Lower bound of the interval.
upperBound Upper bound of the interval.

Returns

float2 The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].

Description

Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are float2 vectors.


Declaration

public static float3 clamp(float3 valueToClamp, float3 lowerBound, float3 upperBound);

Parameters

Parameter Description
valueToClamp Input value to be clamped.
lowerBound Lower bound of the interval.
upperBound Upper bound of the interval.

Returns

float3 The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].

Description

Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are float3 vectors.


Declaration

public static float4 clamp(float4 valueToClamp, float4 lowerBound, float4 upperBound);

Parameters

Parameter Description
valueToClamp Input value to be clamped.
lowerBound Lower bound of the interval.
upperBound Upper bound of the interval.

Returns

float4 The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].

Description

Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are float4 vectors.


Declaration

public static double clamp(double valueToClamp, double lowerBound, double upperBound);

Parameters

Parameter Description
valueToClamp Input value to be clamped.
lowerBound Lower bound of the interval.
upperBound Upper bound of the interval.

Returns

double The clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].

Description

Returns the result of clamping the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are double values.


Declaration

public static double2 clamp(double2 valueToClamp, double2 lowerBound, double2 upperBound);

Parameters

Parameter Description
valueToClamp Input value to be clamped.
lowerBound Lower bound of the interval.
upperBound Upper bound of the interval.

Returns

double2 The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].

Description

Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are double2 vectors.


Declaration

public static double3 clamp(double3 valueToClamp, double3 lowerBound, double3 upperBound);

Parameters

Parameter Description
valueToClamp Input value to be clamped.
lowerBound Lower bound of the interval.
upperBound Upper bound of the interval.

Returns

double3 The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].

Description

Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are double3 vectors.


Declaration

public static double4 clamp(double4 valueToClamp, double4 lowerBound, double4 upperBound);

Parameters

Parameter Description
valueToClamp Input value to be clamped.
lowerBound Lower bound of the interval.
upperBound Upper bound of the interval.

Returns

double4 The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].

Description

Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are double4 vectors.