public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
From: tthomas@sourceware.org
To: frysk-cvs@sourceware.org
Subject: [SCM]  master: Use BigFloatingPoint for arithmetic operations.
Date: Wed, 23 Jan 2008 19:23:00 -0000	[thread overview]
Message-ID: <20080123192318.19722.qmail@sourceware.org> (raw)

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 <tthomas@redhat.com>
Date:   Wed Jan 23 14:14:53 2008 -0500

    Use BigFloatingPoint for arithmetic operations.
    
     frysk-core/frysk/value/ChangeLog
    2008-01-23  Teresa Thomas  <tthomas@redhat.com>
    
    	* 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 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-	<name>frysk.patches</name>
-	<comment></comment>
-	<projects>
-	</projects>
-	<buildSpec>
-		<buildCommand>
-			<name>org.python.pydev.PyDevBuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
-			<triggers>full,incremental,</triggers>
-			<arguments>
-				<dictionary>
-					<key>LaunchConfigHandle</key>
-					<value>&lt;project&gt;/.externalToolBuilders/Create Bin dir.launch</value>
-				</dictionary>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
-			<triggers>full,incremental,</triggers>
-			<arguments>
-				<dictionary>
-					<key>LaunchConfigHandle</key>
-					<value>&lt;project&gt;/.externalToolBuilders/Autogen.sh.launch</value>
-				</dictionary>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
-			<triggers>full,incremental,</triggers>
-			<arguments>
-				<dictionary>
-					<key>LaunchConfigHandle</key>
-					<value>&lt;project&gt;/.externalToolBuilders/Make.launch</value>
-				</dictionary>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
-			<triggers>full,incremental,</triggers>
-			<arguments>
-				<dictionary>
-					<key>LaunchConfigHandle</key>
-					<value>&lt;project&gt;/.externalToolBuilders/org.eclipse.jdt.core.javabuilder.launch</value>
-				</dictionary>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
-			<triggers>full,incremental,</triggers>
-			<arguments>
-				<dictionary>
-					<key>LaunchConfigHandle</key>
-					<value>&lt;project&gt;/.externalToolBuilders/Make Check.launch</value>
-				</dictionary>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
-			<triggers>clean,</triggers>
-			<arguments>
-				<dictionary>
-					<key>LaunchConfigHandle</key>
-					<value>&lt;project&gt;/.externalToolBuilders/Cleaner.launch</value>
-				</dictionary>
-			</arguments>
-		</buildCommand>
-	</buildSpec>
-	<natures>
-		<nature>org.eclipse.jdt.core.javanature</nature>
-		<nature>org.python.pydev.pythonNature</nature>
-	</natures>
-	<linkedResources>
-		<link>
-			<name>build</name>
-			<type>2</type>
-			<locationURI>build</locationURI>
-		</link>
-	</linkedResources>
-</projectDescription>
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  <tthomas@redhat.com>
+
+	* 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  <mwielaard@redhat.com>
 
 	* 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


                 reply	other threads:[~2008-01-23 19:23 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=20080123192318.19722.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: link
Be 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).