Skip to content

Commit

Permalink
fix: display all digits of the binary representation
Browse files Browse the repository at this point in the history
  • Loading branch information
2No2Name authored and hp3721 committed Sep 5, 2022
1 parent abce4d8 commit 8e551b9
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/main/java/mendedminecarts/MinecartDisplayData.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,17 @@ public static String doubleToBinaryString(double d) {
// values have a 1 implicit bit.
answer.append(subnormal ? "0." : "1.");

// Isolate the low-order 49 digits of the binary
// Isolate the low-order 52 digits of the binary
// representation. If all the digits are zero,
// replace with a single 0; otherwise, remove all
// trailing zeros.
String signif = Long.toBinaryString(signifBits).substring(12, 61);
answer.append(signif.equals("0000000000000000000000000000000000000000000000000") ? // 49 zeros
"0" :
signif.replaceFirst("0{1,48}$", ""));
String signif = Long.toBinaryString(signifBits).substring(9, 61);
answer.append(signif);
//always display all trailing 0s for now.
//remove trailing 0s:
// signif.equals("0000000000000000000000000000000000000000000000000000") ? // 52 zeros
// "0" :
// signif.replaceFirst("0{1,51}$", ""));

answer.append('p');
// If the value is subnormal, use the E_min exponent
Expand Down

0 comments on commit 8e551b9

Please sign in to comment.