Package com.dkt.graphics.utils
Class MathUtils
java.lang.Object
com.dkt.graphics.utils.MathUtils
- Author:
- Federico Vera <[email protected]>
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
abs
(int n) Computes the absolute value of a number without branching
The original code can be found in: ...static double
boxcar
(double t, double a, double b) Boxcar functionstatic double
hs
(double t) This class is the Heaviside step function omitting the value of1/2
fort = 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: ...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: ...static double
rect
(double t) Rectangular function
-
Method Details
-
hs
public static double hs(double t) This class is the Heaviside step function omitting the value of1/2
fort = 0
- Parameters:
t
- parameter- Returns:
0
ift < 0
and1
otherwise
-
rect
public static double rect(double t) Rectangular function- Parameters:
t
- parameter- Returns:
1
if-0.5 <= t <= 0.5
and0
otherwise- See Also:
-
boxcar
public static double boxcar(double t, double a, double b) Boxcar function- Parameters:
t
- parametera
- the left boundb
- the right bound- Returns:
1
ifa <= t <= b
and0
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: ...- Parameters:
a
- first value to compareb
- 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: ...- Parameters:
a
- first value to compareb
- 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: ...- Parameters:
n
- number- Returns:
- the absolute value of this number
-