You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DoubleMath goes well with doubles (obviously), but there should be some tool to work with common numbers (or any numbers) without using pretty dangerous for general cases DoubleMath#asDouble all the time.
Implement class NumberMath with these methods:
#equals(Number, Number):boolean
#greaterThan(Number, Number):boolean
#greaterThanOrEquals(Number, Number):boolean
#lessThan(Number, Number):boolean
#lessThanOrEquals(Number, Number):boolean
#isZero(Number):boolean
#isPositive(Number):boolean
#isNegative(Number):boolean
Rules for comparison are these:
Two nulls are equal.
Null is neither greater, nor lower than any other number or null.
Double.NaN is equal to itself, by double comparison rules.
Float.NaN is equal to itself, by float comparison rules.
Float.NaN is equal to Double.NaN, by float widening rules.
Both Double.NaN and Float.NaN are neither greater, nor lower than any other number or NaN.
If both numbers are of the same class that implements Comparable and it's not Double or Float - they should be compared by their implementation.
DoubleMath.compare should be used for any other cases.
Note: this class may be dangerous for it uses exceptional rules for native doubles and floats and generalizes any other numbers.
Note: this class may be dangerous for it will compare any numbers of different kind by their double value, which may be invalid. Though util is coined to cover 95% of generally simple cases where numbers are neither greater than max double, nor lower than min double, and generally may be intercompared.
DoubleMath
goes well with doubles (obviously), but there should be some tool to work with common numbers (or any numbers) without using pretty dangerous for general casesDoubleMath#asDouble
all the time.Implement class
NumberMath
with these methods:#equals(Number, Number):boolean
#greaterThan(Number, Number):boolean
#greaterThanOrEquals(Number, Number):boolean
#lessThan(Number, Number):boolean
#lessThanOrEquals(Number, Number):boolean
#isZero(Number):boolean
#isPositive(Number):boolean
#isNegative(Number):boolean
Rules for comparison are these:
Double.NaN
is equal to itself, by double comparison rules.Float.NaN
is equal to itself, by float comparison rules.Float.NaN
is equal toDouble.NaN
, by float widening rules.Double.NaN
andFloat.NaN
are neither greater, nor lower than any other number orNaN
.Comparable
and it's notDouble
orFloat
- they should be compared by their implementation.DoubleMath.compare
should be used for any other cases.Note: this class may be dangerous for it uses exceptional rules for native doubles and floats and generalizes any other numbers.
Note: this class may be dangerous for it will compare any numbers of different kind by their double value, which may be invalid. Though util is coined to cover 95% of generally simple cases where numbers are neither greater than max double, nor lower than min double, and generally may be intercompared.
Related to: #115
Also implement class
NumberMath.Instance
that may be instantiated with predefined EPS.Related to: #116
The text was updated successfully, but these errors were encountered: