public inbox for frysk-cvs@sourceware.org help / color / mirror / Atom feed
From: tthomas@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Format floating points as hex constants for '-format x'. Date: Thu, 24 Jan 2008 19:20:00 -0000 [thread overview] Message-ID: <20080124192007.25817.qmail@sourceware.org> (raw) The branch, master has been updated via 6a3ed1921c83fce6bac4eadda31dfa9c014f2952 (commit) via 3b2032446949ae5935c6db08378e15fcbcd88609 (commit) from aa1f7ca43e95329845f4e504d5cc7190074f6fc9 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 6a3ed1921c83fce6bac4eadda31dfa9c014f2952 Author: Teresa <tthomas@redhat.com> Date: Thu Jan 24 14:14:27 2008 -0500 Format floating points as hex constants for '-format x'. frysk-core/frysk/value/ChangeLog 2008-01-24 Teresa Thomas <tthomas@redhat.com> * FloatingPointType.java (printAsHexConstant): New. * Format.java (printHexadecimalFP): Call printAsHexConstant. * TestFormat.java (testHexadecimal): Update values. commit 3b2032446949ae5935c6db08378e15fcbcd88609 Author: Teresa <tthomas@redhat.com> Date: Thu Jan 24 14:10:26 2008 -0500 Refactor FloatingPoint854Format. frysk-core/frysk/value/ChangeLog 2008-01-24 Teresa Thomas <tthomas@redhat.com> * FloatingPoint854Format.java: Refactor. * BigFloatingPoint.java (divide): Delete. ----------------------------------------------------------------------- Summary of changes: frysk-core/frysk/value/BigFloatingPoint.java | 9 --- frysk-core/frysk/value/ChangeLog | 9 +++ frysk-core/frysk/value/FloatingPoint854Format.java | 69 +++++++++++++++----- frysk-core/frysk/value/FloatingPointType.java | 23 ++++++- frysk-core/frysk/value/Format.java | 11 ++- frysk-core/frysk/value/TestFormat.java | 2 +- 6 files changed, 91 insertions(+), 32 deletions(-) First 500 lines of diff: diff --git a/frysk-core/frysk/value/BigFloatingPoint.java b/frysk-core/frysk/value/BigFloatingPoint.java index 925213d..eac5c3d 100644 --- a/frysk-core/frysk/value/BigFloatingPoint.java +++ b/frysk-core/frysk/value/BigFloatingPoint.java @@ -185,13 +185,4 @@ public class BigFloatingPoint int notEqual(BigFloatingPoint v) { return (value.compareTo(v.value) != 0) ? 1:0; } - - static BigDecimal divide (BigDecimal a, BigDecimal b) { - BigDecimal result[] = a.divideAndRemainder(b); - // FIXME: Use long division? Use BigDecimal's - // divide(BigDecimal,MathContext) when frysk - // moves to java 1.5.0. - double fraction = result[1].doubleValue()/b.doubleValue(); - return result[0].add(BigDecimal.valueOf(fraction)); - } } diff --git a/frysk-core/frysk/value/ChangeLog b/frysk-core/frysk/value/ChangeLog index 1f24bf6..d8e31f7 100644 --- a/frysk-core/frysk/value/ChangeLog +++ b/frysk-core/frysk/value/ChangeLog @@ -1,3 +1,12 @@ +2008-01-24 Teresa Thomas <tthomas@redhat.com> + + * FloatingPointType.java (printAsHexConstant): New. + * Format.java (printHexadecimalFP): Call printAsHexConstant. + * TestFormat.java (testHexadecimal): Update values. + + * FloatingPoint854Format.java: Refactor. + * BigFloatingPoint.java (divide): Delete. + 2008-01-23 Teresa Thomas <tthomas@redhat.com> * BigFloatingPoint.java: Add arithmetic functions. diff --git a/frysk-core/frysk/value/FloatingPoint854Format.java b/frysk-core/frysk/value/FloatingPoint854Format.java index ed3e81e..eb3c108 100644 --- a/frysk-core/frysk/value/FloatingPoint854Format.java +++ b/frysk-core/frysk/value/FloatingPoint854Format.java @@ -56,6 +56,7 @@ public class FloatingPoint854Format private int sizeF; private int sizeE; private int size; + private int integralOfMantissa; private static final BigDecimal two = BigDecimal.ONE.add(BigDecimal.ONE); /** @@ -77,17 +78,40 @@ public class FloatingPoint854Format } BigFloatingPoint unpack (byte[] bytes) { + int s = getSign (bytes); + BigInteger e = getBiasedExponent(bytes); + BigInteger f = getFraction(bytes); + BigInteger maxE = getMaxEValue(); + return toBigFP (s, e, f, maxE); + } + + /** + * @return 0 for negative and 1 for positive values FPs. + */ + int getSign (byte[] bytes) { int sIndex = 0; if (this.size == 12) sIndex = 2; else if (this.size == 16) sIndex = 6; - int s = (((bytes[sIndex] >> 7) & 0x01) == 0) ? -1:1; - BigInteger e = packExponent.unpackUnsigned(bytes); - BigInteger f = packFraction.unpackUnsigned(bytes); - BigInteger maxE = (BigInteger.valueOf(2).pow(sizeE)).subtract - (BigInteger.ONE); - return toBigFP (s, e, f, maxE); + return (((bytes[sIndex] >> 7) & 0x01) == 0) ? 0:1; + } + + BigInteger getBiasedExponent (byte[] bytes) { + return packExponent.unpackUnsigned(bytes); + } + + BigInteger getFraction (byte[] bytes) { + return packFraction.unpackUnsigned(bytes); + } + + int getIntegralOfMantissa (byte[] bytes) { + getMantissa (getFraction(bytes), getBiasedExponent(bytes), sizeF); + return integralOfMantissa; + } + + BigInteger getMaxEValue () { + return (BigInteger.valueOf(2).pow(sizeE)).subtract(BigInteger.ONE); } /** @@ -106,7 +130,13 @@ public class FloatingPoint854Format int trailingZeroes = f.getLowestSetBit(); BigDecimal m = new BigDecimal (f.shiftRight(trailingZeroes)); m = divide (m, two.pow(sizeOfF-trailingZeroes)); - return (e.compareTo(BigInteger.ZERO) == 0)? m : BigDecimal.ONE.add(m); + //return (e.compareTo(BigInteger.ZERO) == 0)? m : BigDecimal.ONE.add(m); + if (e.compareTo(BigInteger.ZERO) == 0) { + integralOfMantissa = 0; + return m; + } + integralOfMantissa = 1; + return BigDecimal.ONE.add(m); } private BigDecimal getMantissaExtended (BigInteger f, int sizeOfF){ @@ -115,7 +145,14 @@ public class FloatingPoint854Format f = f.clearBit(f.bitLength()-1); BigDecimal m = new BigDecimal (f.shiftRight(trailingZeroes)); m = divide (m, two.pow(sizeOfF-trailingZeroes-1)); - return (j == false)? m : BigDecimal.ONE.add(m); + //return (j == false)? m : BigDecimal.ONE.add(m); + if (j == false) { + integralOfMantissa = 0; + return m; + } + integralOfMantissa = 1; + return BigDecimal.ONE.add(m); + } /** @@ -126,8 +163,8 @@ public class FloatingPoint854Format * @param maxE - max possible value of exponent field */ private BigFloatingPoint toBigFP (int s, - BigInteger e, BigInteger f, - BigInteger maxE) { + BigInteger e, BigInteger f, + BigInteger maxE) { BigDecimal m = getMantissa(f, e, sizeF); BigDecimal result = BigDecimal.ZERO; BigDecimal one = BigDecimal.ONE; @@ -141,8 +178,8 @@ public class FloatingPoint854Format } else { // FIXME: 0 or m? - return (s == -1)? new BigFloatingPoint (m, BigFloatingPoint.posInf): - new BigFloatingPoint (m, BigFloatingPoint.negInf); + return (s == 0)? new BigFloatingPoint (m, BigFloatingPoint.posInf): + new BigFloatingPoint (m, BigFloatingPoint.negInf); } } else if (e.compareTo(BigInteger.ZERO) == 0) { @@ -152,16 +189,16 @@ public class FloatingPoint854Format else { result = BigDecimal.ZERO; } - return (s == -1)? new BigFloatingPoint(result): - new BigFloatingPoint(result.negate()); + return (s == 0)? new BigFloatingPoint(result): + new BigFloatingPoint(result.negate()); } else if (e.compareTo(BigInteger.ZERO) > 0 && e.compareTo(maxE) < 0) { if (e.intValue()-halfMaxE < 0) result = divide (one, two.pow(-e.intValue()+halfMaxE)).multiply(m); else result = two.pow(e.intValue()-halfMaxE).multiply(m); - return (s == -1)? new BigFloatingPoint(result): - new BigFloatingPoint(result.negate()); + return (s == 0)? new BigFloatingPoint(result): + new BigFloatingPoint(result.negate()); } else { throw new RuntimeException diff --git a/frysk-core/frysk/value/FloatingPointType.java b/frysk-core/frysk/value/FloatingPointType.java index fce8394..0f2f120 100644 --- a/frysk-core/frysk/value/FloatingPointType.java +++ b/frysk-core/frysk/value/FloatingPointType.java @@ -60,15 +60,15 @@ public class FloatingPointType switch (size) { case 4: format = FloatingPoint854Format.IEEE32; break; - case 8:format = FloatingPoint854Format.IEEE64; + case 8: format = FloatingPoint854Format.IEEE64; break; case 16:format = FloatingPoint854Format.IEEE128; break; case 10:format = FloatingPoint854Format.IEEE80; break; - case 12: format = FloatingPoint854Format.IEEE96; + case 12:format = FloatingPoint854Format.IEEE96; break; - default: format = FloatingPoint854Format.IEEE64; + default:format = FloatingPoint854Format.IEEE64; break; } } @@ -80,6 +80,23 @@ public class FloatingPointType } /** + * Prints value as a hexadecimal float constant. + * eg. double value 9.0 --> 0x1.2p+0 + */ + public void printAsHexConstant (PrintWriter writer, Location loc) { + byte[] bytes = loc.get(order()); + FloatingPoint854Format f = (FloatingPoint854Format)format; + writer.print(f.getSign(bytes)==0? "":"-"); + writer.print("0x"); + writer.print(f.getIntegralOfMantissa(bytes)); + writer.print('.'); + writer.print(f.getFraction(bytes).toString(16)); + writer.print('p'); + writer.print(f.getBiasedExponent(bytes).intValue() + - f.getMaxEValue().intValue()/2); + } + + /** * Return the raw bytes as an unsigned integer. */ BigInteger getBigInteger(Location location) { diff --git a/frysk-core/frysk/value/Format.java b/frysk-core/frysk/value/Format.java index 5bec308..1023fd8 100644 --- a/frysk-core/frysk/value/Format.java +++ b/frysk-core/frysk/value/Format.java @@ -68,11 +68,16 @@ public abstract class Format writer.print(new BigInteger(1, location.get(order)).toString(2)); } private static void printFloatingPoint(PrintWriter writer, - Location location, - FloatingPointType type) { + Location location, + FloatingPointType type) { BigFloatingPoint f = type.getBigFloatingPoint(location); writer.print(f.toString(type.getSize())); } + private static void printHexadecimalFP(PrintWriter writer, + Location location, + FloatingPointType type) { + type.printAsHexConstant(writer, location); + } /** * Print the integer at LOCATION. @@ -113,7 +118,7 @@ public abstract class Format } void print(PrintWriter writer, Location location, FloatingPointType type) { - printHexadecimal(writer, location, type.order()); + printHexadecimalFP(writer, location, type); } void print(PrintWriter writer, Location location, PointerType type) { diff --git a/frysk-core/frysk/value/TestFormat.java b/frysk-core/frysk/value/TestFormat.java index 54030c9..07d434a 100644 --- a/frysk-core/frysk/value/TestFormat.java +++ b/frysk-core/frysk/value/TestFormat.java @@ -110,7 +110,7 @@ public class TestFormat } public void testHexadecimal() { checkFormat(Format.HEXADECIMAL, "0xffffffff", "0xffffffff", - "0x3f800000", "0x4000000000000000", + "0x1.0p0", "0x1.0p1", "0x1020304"); } public void testOctal() { hooks/post-receive -- frysk system monitor/debugger
reply other threads:[~2008-01-24 19:20 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20080124192007.25817.qmail@sourceware.org \ --to=tthomas@sourceware.org \ --cc=frysk-cvs@sourceware.org \ --cc=frysk@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).