aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-08-28 14:11:44 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-08-28 14:11:44 +0200
commit30b3c5bfd4100c34eaea5b7dd15efc841a328d29 (patch)
tree494e3fe4d42f81108cf96850af342e1a62943a83 /src/main/java/at
parent144f3b57f38bbb0953f5f9d5db8cafaad381256d (diff)
downloadskyhanni-30b3c5bfd4100c34eaea5b7dd15efc841a328d29.tar.gz
skyhanni-30b3c5bfd4100c34eaea5b7dd15efc841a328d29.tar.bz2
skyhanni-30b3c5bfd4100c34eaea5b7dd15efc841a328d29.zip
fixed float and double rounding errors
Diffstat (limited to 'src/main/java/at')
-rwxr-xr-xsrc/main/java/at/hannibal2/skyhanni/features/garden/GardenYawAndPitch.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt12
3 files changed, 12 insertions, 6 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenYawAndPitch.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenYawAndPitch.kt
index f569a0f21..ee80ab77b 100755
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenYawAndPitch.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenYawAndPitch.kt
@@ -38,8 +38,8 @@ class GardenYawAndPitch {
if (!config.showAlways && System.currentTimeMillis() > lastChange + (config.timeout * 1000)) return
val displayList = listOf(
- "§aYaw: §f${yaw.toDouble().round(config.yawPrecision)}",
- "§aPitch: §f${pitch.toDouble().round(config.pitchPrecision)}",
+ "§aYaw: §f${yaw.round(config.yawPrecision)}",
+ "§aPitch: §f${pitch.round(config.pitchPrecision)}",
)
if (GardenAPI.inGarden()) {
config.pos.renderStrings(displayList, posLabel = "Yaw and Pitch")
diff --git a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt
index c4e0cbb26..f09e86164 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt
@@ -139,7 +139,7 @@ class ItemAbilityCooldown {
}
}
if (event.soundName == "random.drink") {
- if (event.pitch.round(1) == 1.8 && event.volume == 1.0f) {
+ if (event.pitch.round(1) == 1.8f && event.volume == 1.0f) {
ItemAbility.HOLY_ICE.sound()
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index 08f88ea17..248efd5df 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -119,13 +119,19 @@ object LorenzUtils {
fun Double.round(decimals: Int): Double {
var multiplier = 1.0
repeat(decimals) { multiplier *= 10 }
- return kotlin.math.round(this * multiplier) / multiplier
+ val result = kotlin.math.round(this * multiplier) / multiplier
+ val a = result.toString()
+ val b = toString()
+ return if (a.length > b.length) this else result
}
- fun Float.round(decimals: Int): Double {
+ fun Float.round(decimals: Int): Float {
var multiplier = 1.0
repeat(decimals) { multiplier *= 10 }
- return kotlin.math.round(this * multiplier) / multiplier
+ val result = kotlin.math.round(this * multiplier) / multiplier
+ val a = result.toString()
+ val b = toString()
+ return if (a.length > b.length) this else result.toFloat()
}
// TODO replace all calls with regex