Skip to content

Commit

Permalink
Return 1 for digit lenght when number is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
ionspin committed Apr 13, 2021
1 parent b40c771 commit ec89c09
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,9 @@ class BigInteger internal constructor(wordArray: WordArray, requestedSign: Sign)
}

override fun numberOfDecimalDigits(): Long {
if (isZero()) {
return 1
}
val bitLenght = arithmetic.bitLength(magnitude)
val minDigit = ceil((bitLenght - 1) * LOG_10_OF_2)
// val maxDigit = floor(bitLenght * LOG_10_OF_2) + 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,12 @@ class ReportedIssueReplicationTest {
val result = a.divide(b, DecimalMode(3, RoundingMode.ROUND_HALF_AWAY_FROM_ZERO, 1))
result == 10.1.toBigDecimal() && result.precision == 3L
}

assertTrue {
val a = 1.toBigDecimal(decimalMode = DecimalMode(3, RoundingMode.ROUND_HALF_AWAY_FROM_ZERO, 4))
val b = (-1).toBigDecimal(decimalMode = DecimalMode(3, RoundingMode.ROUND_HALF_AWAY_FROM_ZERO, 4))
val result = a + b
result == BigDecimal.ZERO
}
}
}

0 comments on commit ec89c09

Please sign in to comment.