fixes a rounding issue

This commit is contained in:
hneemann 2021-01-22 12:40:01 +01:00
parent f0a1b16e9a
commit c7310eff28

View File

@ -225,9 +225,9 @@ public final class Bits {
private static long decodeFixed(String str) throws NumberFormatException { private static long decodeFixed(String str) throws NumberFormatException {
int p = str.indexOf(':'); int p = str.indexOf(':');
try { try {
int frac = Integer.parseInt(str.substring(p + 1)); int frac = Math.abs(Integer.parseInt(str.substring(p + 1)));
double floating = Double.parseDouble(str.substring(0, p)); double floating = Double.parseDouble(str.substring(0, p));
return (long) (floating * (1L << frac)); return Math.round(floating * (1L << frac));
} catch (java.lang.NumberFormatException e) { } catch (java.lang.NumberFormatException e) {
throw new NumberFormatException(str, 0); throw new NumberFormatException(str, 0);
} }