## Class MathUtils

• java.lang.Object
• com.dkt.graphics.utils.MathUtils

• ```public class MathUtils
extends java.lang.Object```
• ### Method Summary

All Methods
Modifier and Type Method Description
`static int` `abs​(int n)`
Computes the absolute value of a number without branching
The original code can be found in: http://graphics.stanford.edu/~seander/bithacks.html#IntegerAbs
`static double` ```boxcar​(double t, double a, double b)```
Boxcar function
`static double` `hs​(double t)`
This class is the Heaviside step function omitting the value of `1/2` for `t = 0`
`static int` ```max​(int a, int b)```
Provides an unbranched version of max for POSITIVE ints, it does 7 operation instead of branching (which is somewhat slower, but it's mainly here for educational purposes)
The original code can be found in: http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax
`static int` ```min​(int a, int b)```
Provides an unbranched version of min for POSITIVE ints, it does 7 operations instead of branching (which is somewhat slower, but it's mainly here for educational purposes)
The original code can be found in: http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax
`static double` `rect​(double t)`
Rectangular function
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Method Detail

• #### hs

`public static double hs​(double t)`
This class is the Heaviside step function omitting the value of `1/2` for `t = 0`
Parameters:
`t` - parameter
Returns:
`0` if `t < 0` and `1` otherwise
• #### rect

`public static double rect​(double t)`
Rectangular function
Parameters:
`t` - parameter
Returns:
`1` if `-0.5 <= t <= 0.5` and `0` otherwise
`boxcar(double, double, double)`
• #### boxcar

```public static double boxcar​(double t,
double a,
double b)```
Boxcar function
Parameters:
`t` - parameter
`a` - the left bound
`b` - the right bound
Returns:
`1` if `a <= t <= b` and `0` otherwise
• #### min

```public static int min​(int a,
int b)```
Provides an unbranched version of min for POSITIVE ints, it does 7 operations instead of branching (which is somewhat slower, but it's mainly here for educational purposes)
The original code can be found in: http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax
Parameters:
`a` - first value to compare
`b` - second value to compare
Returns:
the smallest number
• #### max

```public static int max​(int a,
int b)```
Provides an unbranched version of max for POSITIVE ints, it does 7 operation instead of branching (which is somewhat slower, but it's mainly here for educational purposes)
The original code can be found in: http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax
Parameters:
`a` - first value to compare
`b` - second value to compare
Returns:
the biggest number
• #### abs

`public static int abs​(int n)`
Computes the absolute value of a number without branching
The original code can be found in: http://graphics.stanford.edu/~seander/bithacks.html#IntegerAbs
Parameters:
`n` - number
Returns:
the absolute value of this number