From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19766 invoked by alias); 23 Jan 2008 19:23:20 -0000 Received: (qmail 19737 invoked by uid 9708); 23 Jan 2008 19:23:19 -0000 Date: Wed, 23 Jan 2008 19:23:00 -0000 Message-ID: <20080123192318.19722.qmail@sourceware.org> From: tthomas@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Use BigFloatingPoint for arithmetic operations. X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: c58823fffbb2d85b9503b1bdc703c6c4be377318 X-Git-Newrev: 5e7303f366dbcbf9ca9456bc9ec15b40e27dda5a Mailing-List: contact frysk-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-cvs-owner@sourceware.org Reply-To: frysk@sourceware.org X-SW-Source: 2008-q1/txt/msg00105.txt.bz2 The branch, master has been updated via 5e7303f366dbcbf9ca9456bc9ec15b40e27dda5a (commit) from c58823fffbb2d85b9503b1bdc703c6c4be377318 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 5e7303f366dbcbf9ca9456bc9ec15b40e27dda5a Author: Teresa Date: Wed Jan 23 14:14:53 2008 -0500 Use BigFloatingPoint for arithmetic operations. frysk-core/frysk/value/ChangeLog 2008-01-23 Teresa Thomas * BigFloatingPoint.java: Add arithmetic functions. * FloatingPointUnit.java: Use BigFloatingPoint for arithmetics. * Value.java (asBigFloatingPoint): Fix cast. * IntegerType.java (putBigFloatingPoint): New. * FloatingPointType.java (putBigFloatingPoint): New. * ArithmeticType.java (putBigFloatingPoint): New. ----------------------------------------------------------------------- Summary of changes: .project | 85 ------------------------- frysk-core/frysk/value/ArithmeticType.java | 16 +++++- frysk-core/frysk/value/BigFloatingPoint.java | 59 ++++++++++++++++- frysk-core/frysk/value/ChangeLog | 10 +++ frysk-core/frysk/value/FloatingPointType.java | 11 ++-- frysk-core/frysk/value/FloatingPointUnit.java | 28 ++++---- frysk-core/frysk/value/IntegerType.java | 4 + frysk-core/frysk/value/Value.java | 2 +- 8 files changed, 106 insertions(+), 109 deletions(-) delete mode 100644 .project First 500 lines of diff: diff --git a/.project b/.project deleted file mode 100644 index 9c5213b..0000000 --- a/.project +++ /dev/null @@ -1,85 +0,0 @@ - - - frysk.patches - - - - - - org.python.pydev.PyDevBuilder - - - - - org.eclipse.ui.externaltools.ExternalToolBuilder - full,incremental, - - - LaunchConfigHandle - <project>/.externalToolBuilders/Create Bin dir.launch - - - - - org.eclipse.ui.externaltools.ExternalToolBuilder - full,incremental, - - - LaunchConfigHandle - <project>/.externalToolBuilders/Autogen.sh.launch - - - - - org.eclipse.ui.externaltools.ExternalToolBuilder - full,incremental, - - - LaunchConfigHandle - <project>/.externalToolBuilders/Make.launch - - - - - org.eclipse.ui.externaltools.ExternalToolBuilder - full,incremental, - - - LaunchConfigHandle - <project>/.externalToolBuilders/org.eclipse.jdt.core.javabuilder.launch - - - - - org.eclipse.ui.externaltools.ExternalToolBuilder - full,incremental, - - - LaunchConfigHandle - <project>/.externalToolBuilders/Make Check.launch - - - - - org.eclipse.ui.externaltools.ExternalToolBuilder - clean, - - - LaunchConfigHandle - <project>/.externalToolBuilders/Cleaner.launch - - - - - - org.eclipse.jdt.core.javanature - org.python.pydev.pythonNature - - - - build - 2 - build - - - diff --git a/frysk-core/frysk/value/ArithmeticType.java b/frysk-core/frysk/value/ArithmeticType.java index 170bac7..2ab8722 100644 --- a/frysk-core/frysk/value/ArithmeticType.java +++ b/frysk-core/frysk/value/ArithmeticType.java @@ -102,6 +102,15 @@ public abstract class ArithmeticType putBigInteger(l, val); return new Value(this, l); } + + /** + * Create a new Value of THIS Type, initialized to VAL. + */ + Value createValue(BigFloatingPoint val) { + Location l = new ScratchLocation(getSize()); + putBigFloatingPoint(l, val); + return new Value(this, l); + } /** * Create a new Value of THIS type, initialized to the long VAL. * @@ -135,7 +144,12 @@ public abstract class ArithmeticType * the value should be zero or sign extended. */ abstract void putBigInteger(Location location, BigInteger val); - + /** + * Re-write the entire location with the big floating point value. This + * does not do type conversion. The underlying type determines if + * the value should be zero or sign extended. + */ + abstract void putBigFloatingPoint(Location location, BigFloatingPoint val); /** * Return the arthmetic type converted to a BigInteger, this may * involve truncation and/or rounding. diff --git a/frysk-core/frysk/value/BigFloatingPoint.java b/frysk-core/frysk/value/BigFloatingPoint.java index 3c8e1d9..925213d 100644 --- a/frysk-core/frysk/value/BigFloatingPoint.java +++ b/frysk-core/frysk/value/BigFloatingPoint.java @@ -41,9 +41,10 @@ package frysk.value; import java.math.BigDecimal; import java.math.BigInteger; +import java.math.RoundingMode; /** - * Floating point type - uses java.math.BigDecimal. + * Floating point type - wrapper around java.math.BigDecimal. */ public class BigFloatingPoint { @@ -109,9 +110,9 @@ public class BigFloatingPoint public String toString(int size) { String retValue; switch (encoding) { - // FIXME: Use BigDecimal's toString + // FIXME: Use BigDecimal's toString case 0: - if (size < 8) + if (size < 8) retValue = Float.toString(floatValue()); else retValue = Double.toString(doubleValue()); @@ -141,4 +142,56 @@ public class BigFloatingPoint return (o.getValue().compareTo(this.value) == 0 && o.getEncoding() == this.encoding); } + + /* + * Wrapper functions for arithmetic operations + * on BigFloatingPoint + */ + BigFloatingPoint add (BigFloatingPoint v) { + return new BigFloatingPoint (this.value.add(v.value)); + } + BigFloatingPoint subtract (BigFloatingPoint v) { + return new BigFloatingPoint (this.value.subtract(v.value)); + } + BigFloatingPoint multiply (BigFloatingPoint v) { + return new BigFloatingPoint (this.value.multiply(v.value)); + } + /** + * Returns result rounded towards "nearest neighbor" unless + * both neighbors are equidistant, in which case round up + */ + BigFloatingPoint divide (BigFloatingPoint v) { + return new BigFloatingPoint (value.divide(v.value, RoundingMode.HALF_UP)); + } + BigFloatingPoint mod (BigFloatingPoint v) { + return new BigFloatingPoint (value.remainder(v.value)); + } + + int lessThan (BigFloatingPoint v) { + return (value.compareTo(v.value) < 0) ? 1:0; + } + int greaterThan (BigFloatingPoint v) { + return (value.compareTo(v.value) > 0) ? 1:0; + } + int lessThanOrEqualTo (BigFloatingPoint v) { + return (value.compareTo(v.value) <= 0) ? 1:0; + } + int greaterThanOrEqualTo (BigFloatingPoint v) { + return (value.compareTo(v.value) >= 0) ? 1:0; + } + int equal(BigFloatingPoint v) { + return (value.compareTo(v.value) == 0) ? 1:0; + } + 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 9823e32..1f24bf6 100644 --- a/frysk-core/frysk/value/ChangeLog +++ b/frysk-core/frysk/value/ChangeLog @@ -1,3 +1,13 @@ +2008-01-23 Teresa Thomas + + * BigFloatingPoint.java: Add arithmetic functions. + * FloatingPointUnit.java: Use BigFloatingPoint for + arithmetics. + * Value.java (asBigFloatingPoint): Fix cast. + * IntegerType.java (putBigFloatingPoint): New. + * FloatingPointType.java (putBigFloatingPoint): New. + * ArithmeticType.java (putBigFloatingPoint): New. + 2008-01-18 Mark Wielaard * TestClass.java: Add copyright boilerplate. diff --git a/frysk-core/frysk/value/FloatingPointType.java b/frysk-core/frysk/value/FloatingPointType.java index 88ad4df..fce8394 100644 --- a/frysk-core/frysk/value/FloatingPointType.java +++ b/frysk-core/frysk/value/FloatingPointType.java @@ -52,7 +52,7 @@ public class FloatingPointType extends ArithmeticType { - private FloatingPointFormat format; + private FloatingPointFormat format; public FloatingPointType(String name, ByteOrder order, int size) { super(name, order, size); @@ -78,7 +78,7 @@ public class FloatingPointType // double-dispatch. format.print(writer, location, this); } - + /** * Return the raw bytes as an unsigned integer. */ @@ -86,12 +86,13 @@ public class FloatingPointType return new BigInteger(1, location.get(order())); } - /** - * Return the raw bytes as an unsigned integer. - */ void putBigInteger(Location location, BigInteger val) { location.put(order(), val.toByteArray(), 0); } + + void putBigFloatingPoint(Location location, BigFloatingPoint val) { + location.put(order(), this.format.pack(val, this.getSize()), 0); + } BigFloatingPoint getBigFloatingPoint(Location location) { return format.unpack(location.get(order())); diff --git a/frysk-core/frysk/value/FloatingPointUnit.java b/frysk-core/frysk/value/FloatingPointUnit.java index 01cfb41..3d6f999 100644 --- a/frysk-core/frysk/value/FloatingPointUnit.java +++ b/frysk-core/frysk/value/FloatingPointUnit.java @@ -59,47 +59,47 @@ public class FloatingPointUnit public Value add(Value v1, Value v2) { return retType.createValue - (v1.doubleValue() + v2.doubleValue()); + (v1.asBigFloatingPoint().add(v2.asBigFloatingPoint())); } public Value subtract(Value v1, Value v2) { return retType.createValue - (v1.doubleValue() - v2.doubleValue()); + (v1.asBigFloatingPoint().subtract(v2.asBigFloatingPoint())); } public Value multiply (Value v1, Value v2) { - return retType.createValue - (v1.doubleValue() * v2.doubleValue()); + return retType.createValue + (v1.asBigFloatingPoint().multiply(v2.asBigFloatingPoint())); } public Value divide (Value v1, Value v2) { - return retType.createValue - (v1.doubleValue() / v2.doubleValue()); + return retType.createValue + (v1.asBigFloatingPoint().divide(v2.asBigFloatingPoint())); } public Value mod (Value v1, Value v2) { - return retType.createValue - (v1.doubleValue() % v2.doubleValue()); + return retType.createValue + (v1.asBigFloatingPoint().mod(v2.asBigFloatingPoint())); } public Value lessThan (Value v1, Value v2) { return intType.createValue - (v1.doubleValue() < v2.doubleValue() ? 1:0); + (v1.asBigFloatingPoint().lessThan(v2.asBigFloatingPoint())); } public Value greaterThan (Value v1, Value v2) { return intType.createValue - (v1.doubleValue() > v2.doubleValue() ? 1:0); + (v1.asBigFloatingPoint().greaterThan(v2.asBigFloatingPoint())); } public Value greaterThanOrEqualTo (Value v1, Value v2) { return intType.createValue - (v1.doubleValue() >= v2.doubleValue() ? 1:0); + (v1.asBigFloatingPoint().greaterThanOrEqualTo(v2.asBigFloatingPoint())); } public Value lessThanOrEqualTo (Value v1, Value v2) { return intType.createValue - (v1.doubleValue() <= v2.doubleValue() ? 1:0); + (v1.asBigFloatingPoint().lessThanOrEqualTo(v2.asBigFloatingPoint())); } public Value equal (Value v1, Value v2) { return intType.createValue - (v1.doubleValue() == v2.doubleValue() ? 1:0); + (v1.asBigFloatingPoint().equal(v2.asBigFloatingPoint())); } public Value notEqual (Value v1, Value v2) { return intType.createValue - (v1.doubleValue() != v2.doubleValue() ? 1:0); + (v1.asBigFloatingPoint().notEqual(v2.asBigFloatingPoint())); } } \ No newline at end of file diff --git a/frysk-core/frysk/value/IntegerType.java b/frysk-core/frysk/value/IntegerType.java index 1cf7b48..8724be3 100644 --- a/frysk-core/frysk/value/IntegerType.java +++ b/frysk-core/frysk/value/IntegerType.java @@ -71,6 +71,10 @@ public abstract class IntegerType return new BigFloatingPoint(getBigInteger(location)); } + void putBigFloatingPoint(Location location, BigFloatingPoint val) { + putBigInteger (location, val.bigIntegerValue()); + } + void assign(Location location, Value value) { BigInteger i = ((ArithmeticType)value.getType()) .bigIntegerValue(value.getLocation()); diff --git a/frysk-core/frysk/value/Value.java b/frysk-core/frysk/value/Value.java index bf27dbd..e7f4db8 100644 --- a/frysk-core/frysk/value/Value.java +++ b/frysk-core/frysk/value/Value.java @@ -115,7 +115,7 @@ public class Value } public BigFloatingPoint asBigFloatingPoint() { - return ((FloatingPointType)type.getUltimateType()).getBigFloatingPoint(location); + return ((ArithmeticType)type.getUltimateType()).getBigFloatingPoint(location); } /** hooks/post-receive -- frysk system monitor/debugger