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

More efficient writing of doubles #1264

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ object SafeNumbers {
val dotOff = s.length + exp + 1
s.append(stripTrailingZeros(dv))
s.insert(dotOff, '.')
} else s.append(dv).append('.').append('0')
} else s.append(dv.toInt).append('.').append('0')
}
s.toString
}
Expand Down Expand Up @@ -288,7 +288,7 @@ object SafeNumbers {
private[this] def stripTrailingZeros(x: Long): Long = {
var q0 = x.toInt
if (
q0 == x || {
q0 == x || x << 56 == 0 && {
q0 = ((x >>> 8) * 2.56e-6).toInt // divide a medium positive long by 100000000
q0 * 100000000L == x
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ object SafeNumbers {
val dotOff = s.length + exp + 1
s.append(stripTrailingZeros(dv))
s.insert(dotOff, '.')
} else s.append(dv).append('.').append('0')
} else s.append(dv.toInt).append('.').append('0')
}
s.toString
}
Expand Down Expand Up @@ -271,19 +271,19 @@ object SafeNumbers {
private[this] def stripTrailingZeros(x: Long): Long = {
var q0 = x.toInt
if (
q0 == x || {
q0 == x || x << 56 == 0 && {
q0 = (Math.multiplyHigh(x, 6189700196426901375L) >>> 25).toInt // divide a positive long by 100000000
(x - q0 * 100000000L).toInt == 0
}
) return stripTrailingZeros(q0).toLong
var y = x
var q1, r1 = 0L
while ({
q1 = y / 100
q1 = Math.multiplyHigh(y >>> 2, 2951479051793528259L) >>> 2 // divide a positive long by 100
r1 = y - q1 * 100
r1 == 0
}) y = q1
q1 = y / 10
q1 = Math.multiplyHigh(y, 7378697629483820647L) >>> 2 // divide a positive long by 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 @@ -165,7 +165,7 @@ object SafeNumbers {
val dotOff = s.length + exp + 1
s.append(stripTrailingZeros(dv))
s.insert(dotOff, '.')
} else s.append(dv).append('.').append('0')
} else s.append(dv.toInt).append('.').append('0')
}
s.toString
}
Expand Down Expand Up @@ -271,7 +271,7 @@ object SafeNumbers {
private[this] def stripTrailingZeros(x: Long): Long = {
var q0 = x.toInt
if (
q0 == x || {
q0 == x || x << 56 == 0 && {
q0 = (x / 100000000L).toInt
(x - q0 * 100000000L).toInt == 0
}
Expand Down