# MathUtils

added in [version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)   
belongs to Maven artifact com.android.support:support-compat:28.0.0-alpha1  
Summary: [Methods](https://developer.android.com/reference/android/support/v4/math/MathUtils#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/support/v4/math/MathUtils#inhmethods) \| [\[Expand All\]](https://developer.android.com/reference/android/support/v4/math/MathUtils#)  

# MathUtils

| This package is part of the Android [support library](https://developer.android.com/topic/libraries/support-library) which is no longer maintained. The support library has been superseded by [AndroidX](https://developer.android.com/jetpack/androidx) which is part of [Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider [migrating](https://developer.android.com/jetpack/androidx/migrate) existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library [class
| mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).


`
public


class
MathUtils
`


`

extends Object


`

`


`

|---|-----------------------------------|
| java.lang.Object                     ||
| ↳ | android.support.v4.math.MathUtils |

<br />

*** ** * ** ***

A utility class providing functions useful for common mathematical operations.

## Summary

|                                                                                                                         ### Public methods                                                                                                                         ||
|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static double` | ` `[clamp](https://developer.android.com/reference/android/support/v4/math/MathUtils#clamp(double, double, double))`(double value, double min, double max) ` This method takes a numerical value and ensures it fits in a given numerical range. |
| ` static float`  | ` `[clamp](https://developer.android.com/reference/android/support/v4/math/MathUtils#clamp(float, float, float))`(float value, float min, float max) ` This method takes a numerical value and ensures it fits in a given numerical range.       |
| ` static int`    | ` `[clamp](https://developer.android.com/reference/android/support/v4/math/MathUtils#clamp(int, int, int))`(int value, int min, int max) ` This method takes a numerical value and ensures it fits in a given numerical range.                   |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v4/math/MathUtils#)From class ` java.lang.Object ` |-------------------|-------------------------------| | ` Object`         | ` clone() `                   | | ` boolean`        | ` equals(Object arg0) `       | | ` void`           | ` finalize() `                | | ` final Class<?>` | ` getClass() `                | | ` int`            | ` hashCode() `                | | ` final void`     | ` notify() `                  | | ` final void`     | ` notifyAll() `               | | ` String`         | ` toString() `                | | ` final void`     | ` wait(long arg0, int arg1) ` | | ` final void`     | ` wait(long arg0) `           | | ` final void`     | ` wait() `                    | ||

## Public methods

### clamp

added in [version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
double clamp (double value, 
                double min, 
                double max)
```

This method takes a numerical value and ensures it fits in a given numerical range. If the
number is smaller than the minimum required by the range, then the minimum of the range will
be returned. If the number is higher than the maximum allowed by the range then the maximum
of the range will be returned.

<br />

|                     Parameters                     ||
|---------|-------------------------------------------|
| `value` | `double`: the value to be clamped. <br /> |
| `min`   | `double`: minimum resulting value. <br /> |
| `max`   | `double`: maximum resulting value. <br /> |

|               Returns               ||
|----------|---------------------------|
| `double` | the clamped value. <br /> |

### clamp

added in [version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
float clamp (float value, 
                float min, 
                float max)
```

This method takes a numerical value and ensures it fits in a given numerical range. If the
number is smaller than the minimum required by the range, then the minimum of the range will
be returned. If the number is higher than the maximum allowed by the range then the maximum
of the range will be returned.

<br />

|                    Parameters                     ||
|---------|------------------------------------------|
| `value` | `float`: the value to be clamped. <br /> |
| `min`   | `float`: minimum resulting value. <br /> |
| `max`   | `float`: maximum resulting value. <br /> |

|              Returns               ||
|---------|---------------------------|
| `float` | the clamped value. <br /> |

### clamp

added in [version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int clamp (int value, 
                int min, 
                int max)
```

This method takes a numerical value and ensures it fits in a given numerical range. If the
number is smaller than the minimum required by the range, then the minimum of the range will
be returned. If the number is higher than the maximum allowed by the range then the maximum
of the range will be returned.

<br />

|                   Parameters                    ||
|---------|----------------------------------------|
| `value` | `int`: the value to be clamped. <br /> |
| `min`   | `int`: minimum resulting value. <br /> |
| `max`   | `int`: maximum resulting value. <br /> |

|             Returns              ||
|-------|---------------------------|
| `int` | the clamped value. <br /> |

-

  ## Classes

  - [MathUtils](https://developer.android.com/reference/android/support/v4/math/MathUtils)