Add goals
This commit is contained in:
@@ -123,22 +123,35 @@ func divide(other: BigNumber) -> BigNumber:
|
||||
|
||||
## Returns 1 if this > other, -1 if this < other, 0 if equal
|
||||
func compare_to(other: BigNumber) -> int:
|
||||
if mantissa == 0.0 and other.mantissa == 0.0: return 0
|
||||
|
||||
if mantissa == 0.0 and other.mantissa == 0.0:
|
||||
return 0
|
||||
|
||||
# Handle zero explicitly before sign/exponent checks.
|
||||
if mantissa == 0.0:
|
||||
return -1 if other.mantissa > 0.0 else 1
|
||||
if other.mantissa == 0.0:
|
||||
return 1 if mantissa > 0.0 else -1
|
||||
|
||||
# Handle signs
|
||||
if mantissa > 0 and other.mantissa <= 0: return 1
|
||||
if mantissa < 0 and other.mantissa >= 0: return -1
|
||||
|
||||
if mantissa > 0 and other.mantissa < 0:
|
||||
return 1
|
||||
if mantissa < 0 and other.mantissa > 0:
|
||||
return -1
|
||||
|
||||
# Both are same sign. Compare exponents first.
|
||||
var sign_mult: int = 1 if mantissa > 0 else -1
|
||||
|
||||
if exponent > other.exponent: return sign_mult
|
||||
if exponent < other.exponent: return -sign_mult
|
||||
|
||||
|
||||
if exponent > other.exponent:
|
||||
return sign_mult
|
||||
if exponent < other.exponent:
|
||||
return -sign_mult
|
||||
|
||||
# Exponents are equal, compare mantissas
|
||||
if mantissa > other.mantissa: return 1
|
||||
if mantissa < other.mantissa: return -1
|
||||
|
||||
if mantissa > other.mantissa:
|
||||
return 1
|
||||
if mantissa < other.mantissa:
|
||||
return -1
|
||||
|
||||
return 0
|
||||
|
||||
func is_greater_than(other: BigNumber) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user