[Mulgara-svn] r1604 - trunk/src/jar/querylang/java/org/mulgara/sparql/parser/cst

pag at mulgara.org pag at mulgara.org
Thu Mar 12 06:56:17 UTC 2009


Author: pag
Date: 2009-03-11 23:56:16 -0700 (Wed, 11 Mar 2009)
New Revision: 1604

Modified:
   trunk/src/jar/querylang/java/org/mulgara/sparql/parser/cst/DecimalLiteral.java
Log:
Updated Decimal to use BigDecimal instead of a long. The integral value was a bug, as this should be floating point capable

Modified: trunk/src/jar/querylang/java/org/mulgara/sparql/parser/cst/DecimalLiteral.java
===================================================================
--- trunk/src/jar/querylang/java/org/mulgara/sparql/parser/cst/DecimalLiteral.java	2009-03-12 06:55:13 UTC (rev 1603)
+++ trunk/src/jar/querylang/java/org/mulgara/sparql/parser/cst/DecimalLiteral.java	2009-03-12 06:56:16 UTC (rev 1604)
@@ -14,7 +14,9 @@
  */
 package org.mulgara.sparql.parser.cst;
 
+import java.math.BigDecimal;
 
+
 /**
  * Represents a Decimal literal number.
  *
@@ -26,45 +28,56 @@
 public class DecimalLiteral implements NumericLiteral {
 
   /** The value of this literal. */
-  private float value;
+  private BigDecimal value;
 
   /**
    * Constructs the literal from a string image.
    * @param value The string image of the value for this literal
    */
   public DecimalLiteral(String s) {
-    this.value = Float.parseFloat(s);
+    this.value = new BigDecimal(s);
   }
 
   /**
    * Constructs the literal.
-   * @param value The floating point value for this literal
+   * @param value The double precision floating point value for this literal
    */
-  public DecimalLiteral(float value) {
-    this.value = value;
+  public DecimalLiteral(double value) {
+    this.value = BigDecimal.valueOf(value);
   }
   
   /**
+   * Constructs the literal.
+   * @param value The long integral value for this literal
+   */
+  public DecimalLiteral(long value) {
+    this.value = BigDecimal.valueOf(value);
+  }
+  
+  /**
    * Retrieve the value as a generic Number.
+   * We deem the loss of precision to double to be acceptable
    * @return A Number object containing the value.
    */
   public Number getValue() {
-    return new Float(value);
+    Number result = value.doubleValue();
+    if (result.equals(Double.NEGATIVE_INFINITY) || result.equals(Double.POSITIVE_INFINITY)) result = value;
+    return result;
   }
 
   /**
    * Retrieve the value as a raw type.
    * @return The internal value.
    */
-  public float getFloat() {
-    return value;
+  public double getDouble() {
+    return value.doubleValue();
   }
 
   /**
    * @see org.mulgara.sparql.parser.cst.Node#getImage()
    */
   public String getImage() {
-    return Float.toString(value);
+    return value.toPlainString();
   }
 
 }




More information about the Mulgara-svn mailing list