public final class MathUtil
extends java.lang.Object
Maybe not always the fastest solution to call in here, but working. Also usable for seeing examples and cutting code for manual inlining.
| Modifier and Type | Method | Description |
|---|---|---|
static void |
assertDouble(double d) |
Asserts that the given double is not invalid for calculation.
|
static boolean |
assertEqual(double d1,
double d2,
double precisionRange) |
Asserts if the given two doubles are equal within the given precision
range by the operation:
|
static MathUtil |
getInstance() |
Returns the singleton instance of this class.
|
static java.lang.Integer |
increment(java.lang.Integer value) |
Raises the given integer by one (bad performance).
|
static boolean |
isDouble(double d) |
Tests that the given double is not invalid for calculation.
|
public static void assertDouble(double d)
throws java.lang.IllegalArgumentException
It must not be one of:
Double.NaNDouble.NEGATIVE_INFINITYDouble.POSITIVE_INFINITYd - the double to test.java.lang.IllegalArgumentException - if the assertion fails.public static boolean assertEqual(double d1,
double d2,
double precisionRange)
Math.abs(d1 - d2) < precision.
Because floating point calculations may involve rounding, calculated float and double values may not be accurate. This routine should be used instead. If called with a very small precision range this routine will not be stable against the rounding of calculated floats but at least prevent a bug report of the findbugs tool. See the Java Language Specification, section 4.2.4.
d1 - a double to check equality to the other given double.d2 - a double to check equality to the other given double.precisionRange - the range to allow differences of the two doubles without
judging a difference - this is typically a small value below
0.5.public static MathUtil getInstance()
This method is useless for now as all methods are static. It may be used in future if VM-global configuration will be put to the state of the instance.
#
public static java.lang.Integer increment(java.lang.Integer value)
Warning: Only use this for testing code or prototypes as a new instance might be created for each call. Use primitive data types when fast calculations are required.
Warning: Never do the following:
Integer count = new Integer(6);
MathUtil.increment(count);
// don't expect count now carries 6.
Integers are immutable.
Write:
Integer count = new Integer(6);
count = MathUtil.increment(count);
value - the value to increase, if null is used a new instance will be
initialized with value 0 and incremented.
Integer.valueOf(int)) value increased by one.public static boolean isDouble(double d)
It must not be one of:
Double.NaNDouble.NEGATIVE_INFINITYDouble.POSITIVE_INFINITYd - the double to test.Copyright © 2001 - 2010 LGPL, All Rights Footloose.