Package mgui.numbers
Class NumberFunctions
java.lang.Object
mgui.numbers.NumberFunctions
public class NumberFunctions
extends java.lang.Object
-
Constructor Summary
Constructors Constructor Description NumberFunctions()
-
Method Summary
Modifier and Type Method Description static int
ceilToOdd(double d)
static int
compare(double d1, double d2, double precision)
Compares two numbers within a given precision (number of zeros).static java.text.DecimalFormat
getDecimalFormat(int decimal_places)
static java.text.DecimalFormat
getDecimalFormat(int decimal_places, boolean dividers)
static MguiDouble
getDifference(MguiNumber n1, MguiNumber n2)
static MguiNumber
getInstance(java.lang.Class<?> clazz, double value)
Returns an instance of an MguiNumber of the specified class and value.static MguiNumber
getInstance(java.lang.String type, double value)
Returns an instance of an MguiNumber of the specified type and valuestatic MguiNumber
getInstance(DataType type, double value)
Returns an instance of an MguiNumber of the specified type and valuestatic int
getMultiple(double d1, double d2)
static double
getNextSquare(double n)
Returns the next highest square numberstatic java.lang.String
getPoint2fStr(org.jogamp.vecmath.Point2f p, java.lang.String pattern)
static java.lang.String
getPoint3dStr(org.jogamp.vecmath.Point3d p, java.lang.String pattern)
static MguiDouble
getProduct(MguiNumber n1, MguiNumber n2)
static MguiDouble
getQuotient(MguiNumber n1, MguiNumber n2)
static java.lang.String
getReasonableFormat(double d)
static java.lang.String
getReasonableString(double d)
static double
getSum(double[] n)
static MguiDouble
getSum(MguiNumber n1, MguiNumber n2)
static double
getValueForObject(java.lang.Object obj)
Determines the numeric value ofobj
and returns it as adouble
.static boolean
isEven(double value)
static boolean
isNumeric(java.lang.Object obj)
Determines whetherobj
is numeric; i.e., an instance ofMguiNumber
(except arBoolean), or a Java primitive wrapper (one ofInteger
,Short
,Float
, orDouble
).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
NumberFunctions
public NumberFunctions()
-
-
Method Details
-
compare
public static int compare(double d1, double d2, double precision)Compares two numbers within a given precision (number of zeros). Returns -1 if d1 < d2, +1 if d1 > d2, zero otherwise.- Parameters:
d1
-d2
-precision
-- Returns:
-
getMultiple
public static int getMultiple(double d1, double d2) -
ceilToOdd
public static int ceilToOdd(double d) -
getInstance
Returns an instance of an MguiNumber of the specified type and value- Parameters:
type
-value
-- Returns:
-
getInstance
Returns an instance of an MguiNumber of the specified class and value. Returnsnull
if instantiation failed.- Parameters:
type
-value
-- Returns:
-
getInstance
Returns an instance of an MguiNumber of the specified type and value- Parameters:
type
- : Name of MguiNumber subclassvalue
-- Returns:
-
getDecimalFormat
public static java.text.DecimalFormat getDecimalFormat(int decimal_places) -
getDecimalFormat
public static java.text.DecimalFormat getDecimalFormat(int decimal_places, boolean dividers) -
getPoint2fStr
public static java.lang.String getPoint2fStr(org.jogamp.vecmath.Point2f p, java.lang.String pattern) -
isEven
public static boolean isEven(double value) -
getPoint3dStr
public static java.lang.String getPoint3dStr(org.jogamp.vecmath.Point3d p, java.lang.String pattern) -
getDifference
-
getProduct
-
getQuotient
-
getSum
-
getNextSquare
public static double getNextSquare(double n)Returns the next highest square number -
getSum
public static double getSum(double[] n) -
getReasonableString
public static java.lang.String getReasonableString(double d) -
getReasonableFormat
public static java.lang.String getReasonableFormat(double d) -
getValueForObject
public static double getValueForObject(java.lang.Object obj)Determines the numeric value ofobj
and returns it as adouble
.obj
must be an instance ofarNumber
, or a Java primitive wrapper (one ofInteger
,Short
,Float
, orDouble
).If
obj
does not satisfy these criteria,Double.NaN
is returned.- Parameters:
obj
-- Returns:
-
isNumeric
public static boolean isNumeric(java.lang.Object obj)Determines whetherobj
is numeric; i.e., an instance ofMguiNumber
(except arBoolean), or a Java primitive wrapper (one ofInteger
,Short
,Float
, orDouble
).- Parameters:
obj
-- Returns:
true
if numeric,false
otherwise.
-