Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Utils] NumberMath #117

Open
vsubhuman opened this issue Dec 13, 2015 · 0 comments
Open

[Utils] NumberMath #117

vsubhuman opened this issue Dec 13, 2015 · 0 comments

Comments

@vsubhuman
Copy link
Member

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:

  1. #equals(Number, Number):boolean
  2. #greaterThan(Number, Number):boolean
  3. #greaterThanOrEquals(Number, Number):boolean
  4. #lessThan(Number, Number):boolean
  5. #lessThanOrEquals(Number, Number):boolean
  6. #isZero(Number):boolean
  7. #isPositive(Number):boolean
  8. #isNegative(Number):boolean

Rules for comparison are these:

  1. Two nulls are equal.
  2. Null is neither greater, nor lower than any other number or null.
  3. Double.NaN is equal to itself, by double comparison rules.
  4. Float.NaN is equal to itself, by float comparison rules.
  5. Float.NaN is equal to Double.NaN, by float widening rules.
  6. Both Double.NaN and Float.NaN are neither greater, nor lower than any other number or NaN.
  7. 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.
  8. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant