Skip to content

Commit ec7b21e

Browse files
committed
fix floating point precision issue for float and double settings
1 parent 2e54ef1 commit ec7b21e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/main/kotlin/com/lambda/config/settings/numeric/DoubleSetting.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import com.lambda.config.settings.NumericSetting
2626
import com.lambda.gui.dsl.ImGuiBuilder
2727
import com.lambda.util.extension.CommandBuilder
2828
import net.minecraft.command.CommandRegistryAccess
29+
import kotlin.math.roundToInt
2930

3031
/**
3132
* @see [com.lambda.config.Configurable]
@@ -47,7 +48,7 @@ class DoubleSetting(
4748
visibility
4849
) {
4950
private var valueIndex: Int
50-
get() = ((value - range.start) / step).toInt()
51+
get() = ((value - range.start) / step).roundToInt()
5152
set(index) {
5253
value = (range.start + index * step).coerceIn(range)
5354
}

src/main/kotlin/com/lambda/config/settings/numeric/FloatSetting.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.lambda.config.settings.NumericSetting
2525
import com.lambda.gui.dsl.ImGuiBuilder
2626
import com.lambda.util.extension.CommandBuilder
2727
import net.minecraft.command.CommandRegistryAccess
28+
import kotlin.math.roundToInt
2829

2930
/**
3031
* @see [com.lambda.config.Configurable]
@@ -46,7 +47,7 @@ class FloatSetting(
4647
visibility
4748
) {
4849
private var valueIndex: Int
49-
get() = ((value - range.start) / step).toInt()
50+
get() = ((value - range.start) / step).roundToInt()
5051
set(index) {
5152
value = (range.start + index * step).coerceIn(range)
5253
}

0 commit comments

Comments
 (0)