public final class DoubleUtils extends Object
Modifier and Type | Method and Description |
---|---|
static boolean |
between(double value,
double value1,
double value2)
Returns true if and only if the given value is between value1 and value2.
|
static int |
compareEps(double a,
double b)
Compare two doubles and returns with an integer similar to
Double.compare(double, double) , but with regards to
a predefined epsilon value. |
static boolean |
equalsEps(double a,
double b)
Checks the the given doubles if they are equals - which means they are closer than a
predefined epsilon value, because comparing two doubles directly is a bad practice.
|
static String |
formatDouble(double value)
Format the given double with four digits precision, but leave it without a decimal point.
|
static int |
hashCodeEps(double value)
Create a hash value of the given double.
|
static boolean |
isZero(double a)
Checks if the given double value is zero using a stricter epsilon value
than
equalsEps(double, double) . |
public static boolean equalsEps(double a, double b)
a
- one of the values to be checkedb
- the other value to be checkedpublic static int compareEps(double a, double b)
Double.compare(double, double)
, but with regards to
a predefined epsilon value. The epsilon value is the same as equalsEps(double, double)
method.
If the equalsEps returns with true this method will return with zero and vice versa.a
- the first value to compareb
- the second value to compareDouble.compare(double, double)
, but with regards to a predefined epsilon valuepublic static int hashCodeEps(double value)
Create a hash value of the given double. It will satisfy the basic rule of equals and hashCode methods that if two values are equals they have to have to same hash code value.
So this class's equalsEps(double, double)
method and this method satisfies this rule:
if two double value gives back true with equalEps than this method will generate the same
hash code for them.
value
- the double value to be used to generate the hash codepublic static boolean isZero(double a)
equalsEps(double, double)
.a
- the double value to be checkedpublic static String formatDouble(double value)
value
- the value to be formattedpublic static boolean between(double value, double value1, double value2)
value
- the value to be checkedvalue1
- the border of the intervalvalue2
- the border of the interval.Copyright © 2014–2020, Printing in 3D. All rights reserved.