# MathUtils

[View Source](https://github.com/material-components/material-components-android/blob/1.14.0/lib/java/com/google/android/material/math/MathUtils.java)

*** ** * ** ***


```
public final class MathUtils
```

<br />

*** ** * ** ***

A class that contains utility methods related to numbers.

## Summary

| ### Constants |
|---|---|
| `static final float` | `https://developer.android.com/reference/com/google/android/material/math/MathUtils#DEFAULT_EPSILON() = 1.0E-4f` Default epsilon value for fuzzy float comparisons. |

| ### Public methods |
|---|---|
| `static boolean` | `https://developer.android.com/reference/com/google/android/material/math/MathUtils#areAllElementsEqual(float[])(float[] array)` Returns whether the array contains all same elements. |
| `static float` | `https://developer.android.com/reference/com/google/android/material/math/MathUtils#dist(float,float,float,float)(float x1, float y1, float x2, float y2)` Returns the distance between two points. |
| `static float` | `https://developer.android.com/reference/com/google/android/material/math/MathUtils#distanceToFurthestCorner(float,float,float,float,float,float)( float pointX, float pointY, float rectLeft, float rectTop, float rectRight, float rectBottom )` Returns the furthest distance from the point defined by pointX and pointY to the four corners of the rectangle defined by rectLeft, rectTop, rectRight, and rectBottom. |
| `static float` | `https://developer.android.com/reference/com/google/android/material/math/MathUtils#floorMod(float,int)(float x, int y)` This returns as similar as `https://developer.android.com/reference/java/lang/Math#floorMod(int,int)`. |
| `static int` | `https://developer.android.com/reference/com/google/android/material/math/MathUtils#floorMod(int,int)(int x, int y)` This is same as `https://developer.android.com/reference/java/lang/Math#floorMod(int,int)`. |
| `static boolean` | `https://developer.android.com/reference/com/google/android/material/math/MathUtils#geq(float,float,float)(float a, float b, float epsilon)` Fuzzy greater than or equal to for floats. |
| `static float` | `https://developer.android.com/reference/com/google/android/material/math/MathUtils#lerp(float,float,float)(float start, float stop, float amount)` Returns the linear interpolation of `amount` between `start` and `stop`. |

## Constants

### DEFAULT_EPSILON

```
public static final float DEFAULT_EPSILON = 1.0E-4f
```

Default epsilon value for fuzzy float comparisons.

## Public methods

### areAllElementsEqual

```
public static boolean areAllElementsEqual(float[] array)
```

Returns whether the array contains all same elements.

| Parameters |
|---|---|
| `float[] array` | Input array of floats. |

### dist

```
public static float dist(float x1, float y1, float x2, float y2)
```

Returns the distance between two points.

### distanceToFurthestCorner

```
public static float distanceToFurthestCorner(
    float pointX,
    float pointY,
    float rectLeft,
    float rectTop,
    float rectRight,
    float rectBottom
)
```

Returns the furthest distance from the point defined by pointX and pointY to the four corners of the rectangle defined by rectLeft, rectTop, rectRight, and rectBottom.

The caller should ensure that the point and rectangle share the same coordinate space.

### floorMod

```
public static float floorMod(float x, int y)
```

This returns as similar as `https://developer.android.com/reference/java/lang/Math#floorMod(int,int)`. Instead it works for float type values. And the re-implementation makes it back compatible to API\<24.

### floorMod

```
public static int floorMod(int x, int y)
```

This is same as `https://developer.android.com/reference/java/lang/Math#floorMod(int,int)`. Re-implementation makes it back compatible to API\<24.

### geq

```
public static boolean geq(float a, float b, float epsilon)
```

Fuzzy greater than or equal to for floats.

Returns true if `a` is greater than or equal to `b`, allowing for `
epsilon` error due to limitations in floating point accuracy.

Does not handle overflow, underflow, infinity, or NaN.

### lerp

```
public static float lerp(float start, float stop, float amount)
```

Returns the linear interpolation of `amount` between `start` and `stop`.