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 provides #compare(double,double):int operation that does not allow nulls, cuz decision whether null is greater or lower than everything else, or should throw NPE is project-specific and is up to the library user.
But! There should be explicit comparison operations except #equals:
#greaterThan(Double,Double):boolean
#greaterThanOrEquals(Double,Double):boolean
#lessThan(Double,Double):boolean
#lessThanOrEquals(Double,Double):boolean
Rules for these methods are:
Two nulls are equal
Null is neither greater, nor lower than any other number or null.
Two NaNs are equal
NaN is neither greater nor lower than any other number or NaN.
Any other values are compared by DoubleMath#compare
Note:NaN comparison rules are consistent with java rules for comparison operations: ==, <, <=, >, >=. Any comparison of NaNexcept equality is false by definition. Though two NaNs are equal.
Note:null comparison rules are same as for NaN. Any comparison of nullexcept equality is false by definition.
Note:
NaN comparison rule breaks consistency between these explicit methods and #compare(double,double):int, cuz latter is forced to return an integer value and uses default comparison rules for double values based on the underlying bits.
Double.NaN by bits comparison is considered to be the smallest number (smaller than negative infinity), but it IS neither greater, nor lower than 12.0 and definitely isn't equal to it.
So any consistency isn't possible in this particular case. Default #compare should be used when you need to sort values, or anything like this. But explicit methods should be used when you need binary answer to comparing two numbers by specific comparison operation.
DoubleMath
provides#compare(double,double):int
operation that does not allow nulls, cuz decision whether null is greater or lower than everything else, or should throw NPE is project-specific and is up to the library user.But! There should be explicit comparison operations except
#equals
:#greaterThan(Double,Double):boolean
#greaterThanOrEquals(Double,Double):boolean
#lessThan(Double,Double):boolean
#lessThanOrEquals(Double,Double):boolean
Rules for these methods are:
DoubleMath#compare
Note:
NaN
comparison rules are consistent with java rules for comparison operations:==, <, <=, >, >=
. Any comparison ofNaN
except equality is false by definition. Though two NaNs are equal.Note:
null
comparison rules are same as forNaN
. Any comparison ofnull
except equality is false by definition.Note:
NaN
comparison rule breaks consistency between these explicit methods and#compare(double,double):int
, cuz latter is forced to return an integer value and uses default comparison rules for double values based on the underlying bits.So, for example:
Double.NaN
by bits comparison is considered to be the smallest number (smaller than negative infinity), but it IS neither greater, nor lower than12.0
and definitely isn't equal to it.So any consistency isn't possible in this particular case. Default
#compare
should be used when you need to sort values, or anything like this. But explicit methods should be used when you need binary answer to comparing two numbers by specific comparison operation.Related to: #116
Note: there should not be overloaded versions of these methods for additional EPS parameter.
DoubleMath.Instance
should be used in case like this.The text was updated successfully, but these errors were encountered: