docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method clamp

    clamp(int, int, int)

    Returns the result of clamping the value x into the interval [a, b], where x, a and b are int values.

    Declaration
    public static int clamp(int x, int a, int b)
    Parameters
    Type Name Description
    int x

    Input value to be clamped.

    int a

    Lower bound of the interval.

    int b

    Upper bound of the interval.

    Returns
    Type Description
    int

    The clamping of the input x into the interval [a, b].

    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.

    Declaration
    public static int2 clamp(int2 x, int2 a, int2 b)
    Parameters
    Type Name Description
    int2 x

    Input value to be clamped.

    int2 a

    Lower bound of the interval.

    int2 b

    Upper bound of the interval.

    Returns
    Type Description
    int2

    The componentwise clamping of the input x into the interval [a, b].

    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.

    Declaration
    public static int3 clamp(int3 x, int3 a, int3 b)
    Parameters
    Type Name Description
    int3 x

    Input value to be clamped.

    int3 a

    Lower bound of the interval.

    int3 b

    Upper bound of the interval.

    Returns
    Type Description
    int3

    The componentwise clamping of the input x into the interval [a, b].

    clamp(int4, int4, int4)

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

    Declaration
    public static int4 clamp(int4 x, int4 a, int4 b)
    Parameters
    Type Name Description
    int4 x

    Input value to be clamped.

    int4 a

    Lower bound of the interval.

    int4 b

    Upper bound of the interval.

    Returns
    Type Description
    int4

    The componentwise clamping of the input x into the interval [a, b].

    clamp(uint, uint, uint)

    Returns the result of clamping the value x into the interval [a, b], where x, a and b are uint values.

    Declaration
    public static uint clamp(uint x, uint a, uint b)
    Parameters
    Type Name Description
    uint x

    Input value to be clamped.

    uint a

    Lower bound of the interval.

    uint b

    Upper bound of the interval.

    Returns
    Type Description
    uint

    The clamping of the input x into the interval [a, b].

    clamp(uint2, uint2, uint2)

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

    Declaration
    public static uint2 clamp(uint2 x, uint2 a, uint2 b)
    Parameters
    Type Name Description
    uint2 x

    Input value to be clamped.

    uint2 a

    Lower bound of the interval.

    uint2 b

    Upper bound of the interval.

    Returns
    Type Description
    uint2

    The componentwise clamping of the input x into the interval [a, b].

    clamp(uint3, uint3, uint3)

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

    Declaration
    public static uint3 clamp(uint3 x, uint3 a, uint3 b)
    Parameters
    Type Name Description
    uint3 x

    Input value to be clamped.

    uint3 a

    Lower bound of the interval.

    uint3 b

    Upper bound of the interval.

    Returns
    Type Description
    uint3

    The componentwise clamping of the input x into the interval [a, b].

    clamp(uint4, uint4, uint4)

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

    Declaration
    public static uint4 clamp(uint4 x, uint4 a, uint4 b)
    Parameters
    Type Name Description
    uint4 x

    Input value to be clamped.

    uint4 a

    Lower bound of the interval.

    uint4 b

    Upper bound of the interval.

    Returns
    Type Description
    uint4

    The componentwise clamping of the input x into the interval [a, b].

    clamp(long, long, long)

    Returns the result of clamping the value x into the interval [a, b], where x, a and b are long values.

    Declaration
    public static long clamp(long x, long a, long b)
    Parameters
    Type Name Description
    long x

    Input value to be clamped.

    long a

    Lower bound of the interval.

    long b

    Upper bound of the interval.

    Returns
    Type Description
    long

    The clamping of the input x into the interval [a, b].

    clamp(ulong, ulong, ulong)

    Returns the result of clamping the value x into the interval [a, b], where x, a and b are ulong values.

    Declaration
    public static ulong clamp(ulong x, ulong a, ulong b)
    Parameters
    Type Name Description
    ulong x

    Input value to be clamped.

    ulong a

    Lower bound of the interval.

    ulong b

    Upper bound of the interval.

    Returns
    Type Description
    ulong

    The clamping of the input x into the interval [a, b].

    clamp(float, float, float)

    Returns the result of clamping the value x into the interval [a, b], where x, a and b are float values.

    Declaration
    public static float clamp(float x, float a, float b)
    Parameters
    Type Name Description
    float x

    Input value to be clamped.

    float a

    Lower bound of the interval.

    float b

    Upper bound of the interval.

    Returns
    Type Description
    float

    The clamping of the input x into the interval [a, b].

    clamp(float2, float2, float2)

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

    Declaration
    public static float2 clamp(float2 x, float2 a, float2 b)
    Parameters
    Type Name Description
    float2 x

    Input value to be clamped.

    float2 a

    Lower bound of the interval.

    float2 b

    Upper bound of the interval.

    Returns
    Type Description
    float2

    The componentwise clamping of the input x into the interval [a, b].

    clamp(float3, float3, float3)

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

    Declaration
    public static float3 clamp(float3 x, float3 a, float3 b)
    Parameters
    Type Name Description
    float3 x

    Input value to be clamped.

    float3 a

    Lower bound of the interval.

    float3 b

    Upper bound of the interval.

    Returns
    Type Description
    float3

    The componentwise clamping of the input x into the interval [a, b].

    clamp(float4, float4, float4)

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

    Declaration
    public static float4 clamp(float4 x, float4 a, float4 b)
    Parameters
    Type Name Description
    float4 x

    Input value to be clamped.

    float4 a

    Lower bound of the interval.

    float4 b

    Upper bound of the interval.

    Returns
    Type Description
    float4

    The componentwise clamping of the input x into the interval [a, b].

    clamp(double, double, double)

    Returns the result of clamping the value x into the interval [a, b], where x, a and b are double values.

    Declaration
    public static double clamp(double x, double a, double b)
    Parameters
    Type Name Description
    double x

    Input value to be clamped.

    double a

    Lower bound of the interval.

    double b

    Upper bound of the interval.

    Returns
    Type Description
    double

    The clamping of the input x into the interval [a, b].

    clamp(double2, double2, double2)

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

    Declaration
    public static double2 clamp(double2 x, double2 a, double2 b)
    Parameters
    Type Name Description
    double2 x

    Input value to be clamped.

    double2 a

    Lower bound of the interval.

    double2 b

    Upper bound of the interval.

    Returns
    Type Description
    double2

    The componentwise clamping of the input x into the interval [a, b].

    clamp(double3, double3, double3)

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

    Declaration
    public static double3 clamp(double3 x, double3 a, double3 b)
    Parameters
    Type Name Description
    double3 x

    Input value to be clamped.

    double3 a

    Lower bound of the interval.

    double3 b

    Upper bound of the interval.

    Returns
    Type Description
    double3

    The componentwise clamping of the input x into the interval [a, b].

    clamp(double4, double4, double4)

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

    Declaration
    public static double4 clamp(double4 x, double4 a, double4 b)
    Parameters
    Type Name Description
    double4 x

    Input value to be clamped.

    double4 a

    Lower bound of the interval.

    double4 b

    Upper bound of the interval.

    Returns
    Type Description
    double4

    The componentwise clamping of the input x into the interval [a, b].


    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • clamp(int, int, int)
    • clamp(int2, int2, int2)
    • clamp(int3, int3, int3)
    • clamp(int4, int4, int4)
    • clamp(uint, uint, uint)
    • clamp(uint2, uint2, uint2)
    • clamp(uint3, uint3, uint3)
    • clamp(uint4, uint4, uint4)
    • clamp(long, long, long)
    • clamp(ulong, ulong, ulong)
    • clamp(float, float, float)
    • clamp(float2, float2, float2)
    • clamp(float3, float3, float3)
    • clamp(float4, float4, float4)
    • clamp(double, double, double)
    • clamp(double2, double2, double2)
    • clamp(double3, double3, double3)
    • clamp(double4, double4, double4)
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)