Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minor bugs in the way FloatRepresentation tool displays subnormal numbers #202

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/rars/tools/FloatRepresentation.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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 @@ -530,7 +530,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>" + expansionFontTag
Expand Down Expand Up @@ -822,6 +822,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 @@ -884,7 +885,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 @@ -974,4 +975,4 @@ public void paintComponent(Graphics g) {
}
}

}
}