# clamp

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

## Definition

* **Type:** Method
* **Namespace:** [Unity.Mathematics](/engine/6000.6/script-reference/unity/mathematics.md)
* **Assembly:** UnityEngine.MathematicsModule

## clamp(int, int, int)

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

```csharp
public static int clamp(int valueToClamp, int lowerBound, int upperBound)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Input value to be clamped.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Lower bound of the interval.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Upper bound of the interval.

### Returns

| Type                                                       | Description                                                                                     |
| ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The clamping of the input valueToClamp into the interval (inclusive) \[lowerBound, upperBound]. |

## clamp(int2, int2, int2)

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

```csharp
public static int2 clamp(int2 valueToClamp, int2 lowerBound, int2 upperBound)
```

### Parameters

**** (\[int2]\(/engine/6000.6/script-reference/unity/mathematics/int2)): Input value to be clamped.**** (\[int2]\(/engine/6000.6/script-reference/unity/mathematics/int2)): Lower bound of the interval.**** (\[int2]\(/engine/6000.6/script-reference/unity/mathematics/int2)): Upper bound of the interval.

### Returns

| Type                                                              | Description                                                                                                   |
| ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| [int2](/engine/6000.6/script-reference/unity/mathematics/int2.md) | The componentwise clamping of the input valueToClamp into the interval (inclusive) \[lowerBound, upperBound]. |

## clamp(int3, int3, int3)

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

```csharp
public static int3 clamp(int3 valueToClamp, int3 lowerBound, int3 upperBound)
```

### Parameters

**** (\[int3]\(/engine/6000.6/script-reference/unity/mathematics/int3)): Input value to be clamped.**** (\[int3]\(/engine/6000.6/script-reference/unity/mathematics/int3)): Lower bound of the interval.**** (\[int3]\(/engine/6000.6/script-reference/unity/mathematics/int3)): Upper bound of the interval.

### Returns

| Type                                                              | Description                                                                                                   |
| ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| [int3](/engine/6000.6/script-reference/unity/mathematics/int3.md) | The componentwise clamping of the input valueToClamp into the interval (inclusive) \[lowerBound, upperBound]. |

## clamp(int4, int4, int4)

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.

```csharp
public static int4 clamp(int4 valueToClamp, int4 lowerBound, int4 upperBound)
```

### Parameters

**** (\[int4]\(/engine/6000.6/script-reference/unity/mathematics/int4)): Input value to be clamped.**** (\[int4]\(/engine/6000.6/script-reference/unity/mathematics/int4)): Lower bound of the interval.**** (\[int4]\(/engine/6000.6/script-reference/unity/mathematics/int4)): Upper bound of the interval.

### Returns

| Type                                                              | Description                                                                                                   |
| ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| [int4](/engine/6000.6/script-reference/unity/mathematics/int4.md) | The componentwise clamping of the input valueToClamp into the interval (inclusive) \[lowerBound, upperBound]. |

## clamp(uint, uint, uint)

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

```csharp
public static uint clamp(uint valueToClamp, uint lowerBound, uint upperBound)
```

### Parameters

**** (\[uint]\(https\://learn.microsoft.com/dotnet/api/system.uint32)): Input value to be clamped.**** (\[uint]\(https\://learn.microsoft.com/dotnet/api/system.uint32)): Lower bound of the interval.**** (\[uint]\(https\://learn.microsoft.com/dotnet/api/system.uint32)): Upper bound of the interval.

### Returns

| Type                                                         | Description                                                                                     |
| ------------------------------------------------------------ | ----------------------------------------------------------------------------------------------- |
| [uint](https://learn.microsoft.com/dotnet/api/system.uint32) | The clamping of the input valueToClamp into the interval (inclusive) \[lowerBound, upperBound]. |

## clamp(uint2, uint2, uint2)

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.

```csharp
public static uint2 clamp(uint2 valueToClamp, uint2 lowerBound, uint2 upperBound)
```

### Parameters

**** (\[uint2]\(/engine/6000.6/script-reference/unity/mathematics/uint2)): Input value to be clamped.**** (\[uint2]\(/engine/6000.6/script-reference/unity/mathematics/uint2)): Lower bound of the interval.**** (\[uint2]\(/engine/6000.6/script-reference/unity/mathematics/uint2)): Upper bound of the interval.

### Returns

| Type                                                                | Description                                                                                                   |
| ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| [uint2](/engine/6000.6/script-reference/unity/mathematics/uint2.md) | The componentwise clamping of the input valueToClamp into the interval (inclusive) \[lowerBound, upperBound]. |

## clamp(uint3, uint3, uint3)

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.

```csharp
public static uint3 clamp(uint3 valueToClamp, uint3 lowerBound, uint3 upperBound)
```

### Parameters

**** (\[uint3]\(/engine/6000.6/script-reference/unity/mathematics/uint3)): Input value to be clamped.**** (\[uint3]\(/engine/6000.6/script-reference/unity/mathematics/uint3)): Lower bound of the interval.**** (\[uint3]\(/engine/6000.6/script-reference/unity/mathematics/uint3)): Upper bound of the interval.

### Returns

| Type                                                                | Description                                                                                                   |
| ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| [uint3](/engine/6000.6/script-reference/unity/mathematics/uint3.md) | The componentwise clamping of the input valueToClamp into the interval (inclusive) \[lowerBound, upperBound]. |

## clamp(uint4, uint4, uint4)

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.

```csharp
public static uint4 clamp(uint4 valueToClamp, uint4 lowerBound, uint4 upperBound)
```

### Parameters

**** (\[uint4]\(/engine/6000.6/script-reference/unity/mathematics/uint4)): Input value to be clamped.**** (\[uint4]\(/engine/6000.6/script-reference/unity/mathematics/uint4)): Lower bound of the interval.**** (\[uint4]\(/engine/6000.6/script-reference/unity/mathematics/uint4)): Upper bound of the interval.

### Returns

| Type                                                                | Description                                                                                                   |
| ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| [uint4](/engine/6000.6/script-reference/unity/mathematics/uint4.md) | The componentwise clamping of the input valueToClamp into the interval (inclusive) \[lowerBound, upperBound]. |

## clamp(long, long, long)

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

```csharp
public static long clamp(long valueToClamp, long lowerBound, long upperBound)
```

### Parameters

**** (\[long]\(https\://learn.microsoft.com/dotnet/api/system.int64)): Input value to be clamped.**** (\[long]\(https\://learn.microsoft.com/dotnet/api/system.int64)): Lower bound of the interval.**** (\[long]\(https\://learn.microsoft.com/dotnet/api/system.int64)): Upper bound of the interval.

### Returns

| Type                                                        | Description                                                                                     |
| ----------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| [long](https://learn.microsoft.com/dotnet/api/system.int64) | The clamping of the input valueToClamp into the interval (inclusive) \[lowerBound, upperBound]. |

## clamp(ulong, ulong, ulong)

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

```csharp
public static ulong clamp(ulong valueToClamp, ulong lowerBound, ulong upperBound)
```

### Parameters

**** (\[ulong]\(https\://learn.microsoft.com/dotnet/api/system.uint64)): Input value to be clamped.**** (\[ulong]\(https\://learn.microsoft.com/dotnet/api/system.uint64)): Lower bound of the interval.**** (\[ulong]\(https\://learn.microsoft.com/dotnet/api/system.uint64)): Upper bound of the interval.

### Returns

| Type                                                          | Description                                                                                     |
| ------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| [ulong](https://learn.microsoft.com/dotnet/api/system.uint64) | The clamping of the input valueToClamp into the interval (inclusive) \[lowerBound, upperBound]. |

## clamp(float, float, float)

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

```csharp
public static float clamp(float valueToClamp, float lowerBound, float upperBound)
```

### Parameters

**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): Input value to be clamped.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): Lower bound of the interval.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): Upper bound of the interval.

### Returns

| Type                                                          | Description                                                                                     |
| ------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| [float](https://learn.microsoft.com/dotnet/api/system.single) | The clamping of the input valueToClamp into the interval (inclusive) \[lowerBound, upperBound]. |

## clamp(float2, float2, float2)

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.

```csharp
public static float2 clamp(float2 valueToClamp, float2 lowerBound, float2 upperBound)
```

### Parameters

**** (\[float2]\(/engine/6000.6/script-reference/unity/mathematics/float2)): Input value to be clamped.**** (\[float2]\(/engine/6000.6/script-reference/unity/mathematics/float2)): Lower bound of the interval.**** (\[float2]\(/engine/6000.6/script-reference/unity/mathematics/float2)): Upper bound of the interval.

### Returns

| Type                                                                  | Description                                                                                                   |
| --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| [float2](/engine/6000.6/script-reference/unity/mathematics/float2.md) | The componentwise clamping of the input valueToClamp into the interval (inclusive) \[lowerBound, upperBound]. |

## clamp(float3, float3, float3)

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.

```csharp
public static float3 clamp(float3 valueToClamp, float3 lowerBound, float3 upperBound)
```

### Parameters

**** (\[float3]\(/engine/6000.6/script-reference/unity/mathematics/float3)): Input value to be clamped.**** (\[float3]\(/engine/6000.6/script-reference/unity/mathematics/float3)): Lower bound of the interval.**** (\[float3]\(/engine/6000.6/script-reference/unity/mathematics/float3)): Upper bound of the interval.

### Returns

| Type                                                                  | Description                                                                                                   |
| --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| [float3](/engine/6000.6/script-reference/unity/mathematics/float3.md) | The componentwise clamping of the input valueToClamp into the interval (inclusive) \[lowerBound, upperBound]. |

## clamp(float4, float4, float4)

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.

```csharp
public static float4 clamp(float4 valueToClamp, float4 lowerBound, float4 upperBound)
```

### Parameters

**** (\[float4]\(/engine/6000.6/script-reference/unity/mathematics/float4)): Input value to be clamped.**** (\[float4]\(/engine/6000.6/script-reference/unity/mathematics/float4)): Lower bound of the interval.**** (\[float4]\(/engine/6000.6/script-reference/unity/mathematics/float4)): Upper bound of the interval.

### Returns

| Type                                                                  | Description                                                                                                   |
| --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| [float4](/engine/6000.6/script-reference/unity/mathematics/float4.md) | The componentwise clamping of the input valueToClamp into the interval (inclusive) \[lowerBound, upperBound]. |

## clamp(double, double, double)

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

```csharp
public static double clamp(double valueToClamp, double lowerBound, double upperBound)
```

### Parameters

**** (\[double]\(https\://learn.microsoft.com/dotnet/api/system.double)): Input value to be clamped.**** (\[double]\(https\://learn.microsoft.com/dotnet/api/system.double)): Lower bound of the interval.**** (\[double]\(https\://learn.microsoft.com/dotnet/api/system.double)): Upper bound of the interval.

### Returns

| Type                                                           | Description                                                                                     |
| -------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| [double](https://learn.microsoft.com/dotnet/api/system.double) | The clamping of the input valueToClamp into the interval (inclusive) \[lowerBound, upperBound]. |

## clamp(double2, double2, double2)

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.

```csharp
public static double2 clamp(double2 valueToClamp, double2 lowerBound, double2 upperBound)
```

### Parameters

**** (\[double2]\(/engine/6000.6/script-reference/unity/mathematics/double2)): Input value to be clamped.**** (\[double2]\(/engine/6000.6/script-reference/unity/mathematics/double2)): Lower bound of the interval.**** (\[double2]\(/engine/6000.6/script-reference/unity/mathematics/double2)): Upper bound of the interval.

### Returns

| Type                                                                    | Description                                                                                                   |
| ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| [double2](/engine/6000.6/script-reference/unity/mathematics/double2.md) | The componentwise clamping of the input valueToClamp into the interval (inclusive) \[lowerBound, upperBound]. |

## clamp(double3, double3, double3)

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.

```csharp
public static double3 clamp(double3 valueToClamp, double3 lowerBound, double3 upperBound)
```

### Parameters

**** (\[double3]\(/engine/6000.6/script-reference/unity/mathematics/double3)): Input value to be clamped.**** (\[double3]\(/engine/6000.6/script-reference/unity/mathematics/double3)): Lower bound of the interval.**** (\[double3]\(/engine/6000.6/script-reference/unity/mathematics/double3)): Upper bound of the interval.

### Returns

| Type                                                                    | Description                                                                                                   |
| ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| [double3](/engine/6000.6/script-reference/unity/mathematics/double3.md) | The componentwise clamping of the input valueToClamp into the interval (inclusive) \[lowerBound, upperBound]. |

## clamp(double4, double4, double4)

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.

```csharp
public static double4 clamp(double4 valueToClamp, double4 lowerBound, double4 upperBound)
```

### Parameters

**** (\[double4]\(/engine/6000.6/script-reference/unity/mathematics/double4)): Input value to be clamped.**** (\[double4]\(/engine/6000.6/script-reference/unity/mathematics/double4)): Lower bound of the interval.**** (\[double4]\(/engine/6000.6/script-reference/unity/mathematics/double4)): Upper bound of the interval.

### Returns

| Type                                                                    | Description                                                                                                   |
| ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| [double4](/engine/6000.6/script-reference/unity/mathematics/double4.md) | The componentwise clamping of the input valueToClamp into the interval (inclusive) \[lowerBound, upperBound]. |
