Skip to content

Commit

Permalink
Simplify stripTrailingZeros (#1273)
Browse files Browse the repository at this point in the history
  • Loading branch information
plokhotnyuk authored Jan 31, 2025
1 parent e6af869 commit 7d2a035
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ object SafeNumbers {
y = q1
z = q1
}
if (r1 == 0) return q1
y
}

Expand Down
13 changes: 4 additions & 9 deletions zio-json/jvm/src/main/scala/zio/json/internal/SafeNumbers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ object SafeNumbers {
val s = vb >> 2
if (
s < 100 || {
dv = Math.multiplyHigh(s, 1844674407370955168L)
dv = Math.multiplyHigh(s, 1844674407370955168L) // divide a positive long by 10
val sp40 = dv * 40
val upin = (vbls - sp40).toInt
(((sp40 + vbrd).toInt + 40) ^ upin) >= 0 || {
Expand Down Expand Up @@ -276,16 +276,11 @@ object SafeNumbers {
(x - q0 * 100000000L).toInt == 0
}
) return stripTrailingZeros(q0).toLong
var y = x
var q1, r1 = 0L
var y, q1 = x
while ({
q1 = y / 100
r1 = y - q1 * 100
r1 == 0
q1 = Math.multiplyHigh(q1, 1844674407370955168L) // divide a positive long by 10
q1 * 10 == y
}) y = q1
q1 = y / 10
r1 = y - q1 * 10
if (r1 == 0) return q1
y
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ object SafeNumbers {
val s = vb >> 2
if (
s < 100 || {
dv = s / 10
dv = NativeMath.multiplyHigh(s, 1844674407370955168L) // divide a positive long by 10
val sp40 = dv * 40
val upin = (vbls - sp40).toInt
(((sp40 + vbrd).toInt + 40) ^ upin) >= 0 || {
Expand Down Expand Up @@ -276,16 +276,11 @@ object SafeNumbers {
(x - q0 * 100000000L).toInt == 0
}
) return stripTrailingZeros(q0).toLong
var y = x
var q1, r1 = 0L
var y, q1 = x
while ({
q1 = y / 100
r1 = y - q1 * 100
r1 == 0
q1 = NativeMath.multiplyHigh(q1, 1844674407370955168L) // divide a positive long by 10
q1 * 10 == y
}) y = q1
q1 = y / 10
r1 = y - q1 * 10
if (r1 == 0) return q1
y
}

Expand Down

0 comments on commit 7d2a035

Please sign in to comment.