In This Article

SingleExtensions Class

Provides extension methods for the float type.

public static class SingleExtensions
Inheritance:
object object

Methods

ClampToNonnegative(float)

Clamps a value to nonnegative number between 0.0..MaxValue.

public static float ClampToNonnegative(this float value)
Parameter Type Description
value float

The value to examine.

Returns

float:

The clamped value.

ClampToPercentage(float)

Clamps a value to a percentage between 0.0..1.0.

public static float ClampToPercentage(this float value)
Parameter Type Description
value float

The value to examine.

Returns

float:

The clamped value.

ClampToRange(float, float, float)

Clamps a value between the specified minimum and maximum.

public static float ClampToRange(this float value, float minimum, float maximum)
Parameter Type Description
value float

The value to examine.

minimum float

The minimum value.

maximum float

The maximum value.

Returns

float:

The clamped value.

IsBetween(float, float, float, bool)

Returns whether a value is between the specified minimum and maximum.

public static bool IsBetween(this float value, float minimum, float maximum, bool isInclusive = true)
Parameter Type Description
value float

The value to examine.

minimum float

The number that the value must be greater than, or equal to if inclusive.

maximum float

The number that the value must be less than, or equal to if inclusive.

isInclusive bool

Whether the check considers minimum and maximum as being inclusive. The default value is true.

Returns

bool:

true if the value is between the specified minimum and maximum; otherwise, false.

IsCloseTo(float, float)

Returns whether a value is close enough with another value to be considered equal.

public static bool IsCloseTo(this float value, float comparison)
Parameter Type Description
value float

The base value.

comparison float

The value to be compared.

Returns

bool:

true if the two values are close enough to be considered equal; otherwise, false.

IsGreaterThan(float, float)

Determines whether the value is effectively greater than the comparison value.

public static bool IsGreaterThan(this float value, float comparison)
Parameter Type Description
value float

The base value.

comparison float

The value to be compared.

Returns

bool:

true if the value is effectively greater than the comparison value; otherwise, false.

IsGreaterThanOrCloseTo(float, float)

Determines whether the value is effectively greater than or equal to the comparison value.

public static bool IsGreaterThanOrCloseTo(this float value, float comparison)
Parameter Type Description
value float

The base value.

comparison float

The value to be compared.

Returns

bool:

true if the value is effectively greater than or equal to the comparison value; otherwise, false.

IsLessThan(float, float)

Determines whether the value is effectively less than the comparison value.

public static bool IsLessThan(this float value, float comparison)
Parameter Type Description
value float

The base value.

comparison float

The value to be compared.

Returns

bool:

true if the value is effectively less than the comparison value; otherwise, false.

IsLessThanOrCloseTo(float, float)

Determines whether the value is effectively less than or equal to the comparison value.

public static bool IsLessThanOrCloseTo(this float value, float comparison)
Parameter Type Description
value float

The base value.

comparison float

The value to be compared.

Returns

bool:

true if the value is effectively less than or equal to the comparison value; otherwise, false.

IsNonnegative(float)

Returns whether a value is inclusively between 0.0..MaxValue.

public static bool IsNonnegative(this float value)
Parameter Type Description
value float

The value to examine.

Returns

bool:

true if the value is inclusively between 0.0..MaxValue; otherwise, false.

IsPercentage(float)

Returns whether a value is a percentage inclusively between 0.0..1.0.

public static bool IsPercentage(this float value)
Parameter Type Description
value float

The value to examine.

Returns

bool:

true if the value is a percentage inclusively between 0.0..1.0; otherwise, false.

IsZero(float)

Determines whether the specified value is close enough to zero to be considered equal.

public static bool IsZero(this float value)
Parameter Type Description
value float

The value to compare with zero.

Returns

bool:

true if the specified value is close enough to zero to be considered equal; otherwise, false.

Round(float, RoundMode)

Returns a number rounded to zero digits using the specified RoundMode.

public static float Round(this float value, RoundMode mode = RoundMode.Nearest)
Parameter Type Description
value float

The value to round.

mode RoundMode

(Optional) The RoundMode to use, whose default is Nearest.

Returns

float:

The rounded value, or the original value when mode is None.

Round(float, int, RoundMode)

Returns a number rounded to the specified number of digits using the specified RoundMode.

public static float Round(this float value, int digits, RoundMode mode = RoundMode.Nearest)
Parameter Type Description
value float

The value to round.

digits int

The number of digits in the result.

mode RoundMode

(Optional) The RoundMode to use, whose default is Nearest.

Returns

float:

The rounded value, or the original value when mode is None.

RoundToMultiple(float, float)

Returns a number rounded to the nearest multiple of another number.

public static float RoundToMultiple(this float value, float multipleOf)
Parameter Type Description
value float

The value to round.

multipleOf float

The number that defines the multiple.

Returns

float

Inherited Members