From 282c6b698ab07d202a0f94a3bb494b1ed600c8d4 Mon Sep 17 00:00:00 2001 From: ghidra1 Date: Mon, 8 Jul 2024 22:34:43 -0400 Subject: [PATCH] GP-4759 corrected BigFloat formatting of -0.0 (Closes #6677) --- .../src/main/java/ghidra/pcode/floatformat/BigFloat.java | 3 +++ .../test/java/ghidra/pcode/floatformat/FloatFormatTest.java | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcode/floatformat/BigFloat.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcode/floatformat/BigFloat.java index 7d452a03002..63967c0761b 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcode/floatformat/BigFloat.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcode/floatformat/BigFloat.java @@ -1042,6 +1042,9 @@ private String formatSpecialCase() { if (isInfinite()) { return sign < 0 ? NEGATIVE_INFINITY : POSITIVE_INFINITY; } + if (isZero()) { + return sign < 0 ? "-0.0" : "0.0"; + } return null; } diff --git a/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/pcode/floatformat/FloatFormatTest.java b/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/pcode/floatformat/FloatFormatTest.java index 63e28b52597..8303fbe953f 100644 --- a/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/pcode/floatformat/FloatFormatTest.java +++ b/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/pcode/floatformat/FloatFormatTest.java @@ -1480,7 +1480,11 @@ private void doTestValueOfBigInteger(BigDecimal bdVal) { @Test public void testValueOfBigInteger() { FloatFormat ff = FloatFormatFactory.getFloatFormat(8); - assertEquals("0.0", ff.toDecimalString(ff.getBigFloat(BigInteger.ZERO))); + + assertFalse(ff.getBigZero(true).equals(ff.getBigZero(false))); + + assertEquals("-0.0", ff.toDecimalString(ff.getBigZero(true))); + assertEquals("0.0", ff.toDecimalString(ff.getBigZero(false))); assertEquals("1.0", ff.toDecimalString(ff.getBigFloat(BigInteger.ONE))); assertEquals("2.0", ff.toDecimalString(ff.getBigFloat(BigInteger.TWO))); assertEquals("-1.0", ff.toDecimalString(ff.getBigFloat(BigInteger.ONE.negate())));