Skip to content

Commit

Permalink
Merge pull request #99 from pacalet/fixFloatRepresentationSubnormal
Browse files Browse the repository at this point in the history
Fix minor bugs in the way FloatRepresentation tool displays subnormal numbers
  • Loading branch information
privat authored Nov 29, 2024
2 parents ef563eb + af7bd3d commit 11f9a9e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/rars/tools/FloatRepresentation.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class FloatRepresentation extends AbstractToolAndApplication {
private static final int maxLengthBinaryFraction = 23;
private static final int maxLengthBinaryTotal = maxLengthBinarySign + maxLengthBinaryExponent + maxLengthBinaryFraction;
private static final int maxLengthDecimal = 20;
private static final String denormalizedLabel = " significand (denormalized - no 'hidden bit')";
private static final String denormalizedLabel = " significand (subnormal - no 'hidden bit')";
private static final String normalizedLabel = " significand ('hidden bit' underlined) ";
private static final Font instructionsFont = new Font("Arial", Font.PLAIN, 14);
private static final Font hexDisplayFont = new Font("Courier", Font.PLAIN, 32);
Expand Down Expand Up @@ -497,7 +497,7 @@ private FlavorsOfFloat buildOneFromInt(int intValue) {
public String buildExpansionFromBinaryString(String binaryString) {
int biasedExponent = Binary.binaryStringToInt(
binaryString.substring(maxLengthBinarySign, maxLengthBinarySign + maxLengthBinaryExponent));
String stringExponent = Integer.toString(biasedExponent - exponentBias);
String stringExponent = Integer.toString(biasedExponent == 0 ? -126 : biasedExponent - exponentBias);
// stringExponent length will range from 1 to 4 (e.g. "0" to "-128") characters.
// Right-pad with HTML spaces (" ") to total length 5 displayed characters.
return "<html><head></head><body>" + (Globals.getSettings().getBooleanSetting(Settings.Bool.DARK_MODE_ENABLED) ? expansionFontTagDark : expansionFontTagLight)
Expand Down Expand Up @@ -789,6 +789,7 @@ public void paintComponent(Graphics g) {
//
class BinaryToDecimalFormulaGraphic extends JPanel {
final String subtractLabelTrailer = " - 127";
final String subnormalLabel = "-126";
final int arrowHeadOffset = 5;
final int lowerY = 0;
final int upperY = 50;
Expand Down Expand Up @@ -851,7 +852,7 @@ private void drawSubtractLabel(Graphics g, String label) {

// format the label for a given integer exponent value...
private String buildSubtractLabel(int value) {
return Integer.toString(value) + subtractLabelTrailer;
return (value == 0) ? subnormalLabel : Integer.toString(value) + subtractLabelTrailer;
}

}
Expand Down Expand Up @@ -941,4 +942,4 @@ public void paintComponent(Graphics g) {
}
}

}
}

0 comments on commit 11f9a9e

Please sign in to comment.