public final class

MathUtils

extends Object
java.lang.Object
   ↳ com.artfulbits.aiCharts.Base.MathUtils

Class Overview

Represents mathematical utilities class.

Summary

Constants
double PIAndHalf
double PIOver2
double PIOver4
double TwoPI
Public Constructors
MathUtils()
Public Methods
static double cellingTo(double value, double div)
Rounds target value to make it multiples div.
static double clamp(double value, double min, double max)
Shifts value to fall into specified interval.
static int clamp(int value, int min, int max)
Shifts value to fall into specified interval.
static double coerce(double value, double interval)
Coerces value to human readable representation.
static boolean equals(Double arg1, double arg2)
This method is deprecated. Unused method. Will be removed.
static double floorTo(double value, double div)
Rounds target value to make it multiples div.
static double round(double value, int degree)
Rounds value to specified degree.
static int solveQuadratic(double a, double b, double c, double[] result)
Determines roots of quadratic equation Ax^2 + Bx + C = 0.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final double PIAndHalf

Constant Value: 4.71238898038469

public static final double PIOver2

Constant Value: 1.5707963267948966

public static final double PIOver4

Constant Value: 0.7853981633974483

public static final double TwoPI

Constant Value: 6.283185307179586

Public Constructors

public MathUtils ()

Public Methods

public static double cellingTo (double value, double div)

Rounds target value to make it multiples div.

Parameters
value target value.
div division.
Returns
  • rounded value.

public static double clamp (double value, double min, double max)

Shifts value to fall into specified interval.

Parameters
value value to shift.
min start of interval.
max end of interval.
Returns
  • min if value < min
    max if value > max
    initial value if value fall in specified interval.

public static int clamp (int value, int min, int max)

Shifts value to fall into specified interval.

Parameters
value value to shift.
min start of interval.
max end of interval.
Returns
  • min if value < min
    max if value > max
    initial value if value fall in specified interval.

public static double coerce (double value, double interval)

Coerces value to human readable representation.

Parameters
value value to coerce.
interval interval that is used to determine range.
Returns
  • coerced value.

public static boolean equals (Double arg1, double arg2)

This method is deprecated.
Unused method. Will be removed.

Determines whether instance of Double arg1 equals arg2.

Parameters
arg1 instance of Double.
arg2 double value to compare.
Returns
  • true if values are equal, otherwise false.

public static double floorTo (double value, double div)

Rounds target value to make it multiples div.

Parameters
value target value.
div division
Returns
  • rounded value.

public static double round (double value, int degree)

Rounds value to specified degree.

Parameters
value value to round.
degree required degree.
Returns
  • rounded value.

public static int solveQuadratic (double a, double b, double c, double[] result)

Determines roots of quadratic equation Ax^2 + Bx + C = 0.

Parameters
a A coefficient.
b B coefficient
c C coefficient
result array of double roots of equation
Returns
  • number of roots or zero if roots could not be found on the real axis.