共用方式為


StrictMath.Clamp Method

Definition

Overloads

Clamp(Double, Double, Double)

Clamps the value to fit between min and max.

Clamp(Int64, Int32, Int32)

Clamps the value to fit between min and max.

Clamp(Int64, Int64, Int64)

Clamps the value to fit between min and max.

Clamp(Single, Single, Single)

Clamps the value to fit between min and max.

Clamp(Double, Double, Double)

Clamps the value to fit between min and max.

[Android.Runtime.Register("clamp", "(DDD)D", "", ApiSince=35)]
public static double Clamp (double value, double min, double max);
[<Android.Runtime.Register("clamp", "(DDD)D", "", ApiSince=35)>]
static member Clamp : double * double * double -> double

Parameters

value
Double

value to clamp

min
Double

minimal allowed value

max
Double

maximal allowed value

Returns

a clamped value that fits into min..max interval

Attributes

Remarks

Clamps the value to fit between min and max. If the value is less than min, then min is returned. If the value is greater than max, then max is returned. Otherwise, the original value is returned. If value is NaN, the result is also NaN.

Unlike the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero. E.g., clamp(-0.0, 0.0, 1.0) returns 0.0.

Added in 21.

Java documentation for java.lang.StrictMath.clamp(double, double, double).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Clamp(Int64, Int32, Int32)

Clamps the value to fit between min and max.

[Android.Runtime.Register("clamp", "(JII)I", "", ApiSince=35)]
public static int Clamp (long value, int min, int max);
[<Android.Runtime.Register("clamp", "(JII)I", "", ApiSince=35)>]
static member Clamp : int64 * int * int -> int

Parameters

value
Int64

value to clamp

min
Int32

minimal allowed value

max
Int32

maximal allowed value

Returns

a clamped value that fits into min..max interval

Attributes

Remarks

Clamps the value to fit between min and max. If the value is less than min, then min is returned. If the value is greater than max, then max is returned. Otherwise, the original value is returned.

While the original value of type long may not fit into the int type, the bounds have the int type, so the result always fits the int type. This allows to use method to safely cast long value to int with saturation.

Added in 21.

Java documentation for java.lang.StrictMath.clamp(long, int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Clamp(Int64, Int64, Int64)

Clamps the value to fit between min and max.

[Android.Runtime.Register("clamp", "(JJJ)J", "", ApiSince=35)]
public static long Clamp (long value, long min, long max);
[<Android.Runtime.Register("clamp", "(JJJ)J", "", ApiSince=35)>]
static member Clamp : int64 * int64 * int64 -> int64

Parameters

value
Int64

value to clamp

min
Int64

minimal allowed value

max
Int64

maximal allowed value

Returns

a clamped value that fits into min..max interval

Attributes

Remarks

Clamps the value to fit between min and max. If the value is less than min, then min is returned. If the value is greater than max, then max is returned. Otherwise, the original value is returned.

Added in 21.

Java documentation for java.lang.StrictMath.clamp(long, long, long).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Clamp(Single, Single, Single)

Clamps the value to fit between min and max.

[Android.Runtime.Register("clamp", "(FFF)F", "", ApiSince=35)]
public static float Clamp (float value, float min, float max);
[<Android.Runtime.Register("clamp", "(FFF)F", "", ApiSince=35)>]
static member Clamp : single * single * single -> single

Parameters

value
Single

value to clamp

min
Single

minimal allowed value

max
Single

maximal allowed value

Returns

a clamped value that fits into min..max interval

Attributes

Remarks

Clamps the value to fit between min and max. If the value is less than min, then min is returned. If the value is greater than max, then max is returned. Otherwise, the original value is returned. If value is NaN, the result is also NaN.

Unlike the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero. E.g., clamp(-0.0f, 0.0f, 1.0f) returns 0.0f.

Added in 21.

Java documentation for java.lang.StrictMath.clamp(float, float, float).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to