FIX: Autoscale scaled wrong for negative exponents

This commit is contained in:
Patrick Haßel 2025-02-25 11:57:40 +01:00
parent 27155cdf19
commit 0b99043d5a

View File

@ -18,7 +18,7 @@ public class Autoscale {
final double abs = sourceUnit.factor * Arrays.stream(values).map(Math::abs).max().orElse(0);
final double exp = Math.max(0, Math.log10(abs));
final int group = (int) Math.floor(exp / 3);
this.factor = sourceUnit.factor * Math.pow(10, group * 3);
this.factor = sourceUnit.factor * Math.pow(10, -group * 3);
final int index = (SI_PREFIX.length - 1) / 2 + group;
this.unit = SI_PREFIX[index] + sourceUnit.base.unit;