jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [1/2] jena git commit: JENA-1070: Use the ".0" form for double to decimal by value.
Date Mon, 16 Nov 2015 21:36:36 GMT
Repository: jena
Updated Branches:
  refs/heads/master 041c4dae1 -> d26fab4a9


JENA-1070: Use the ".0" form for double to decimal by value.


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/c53ef398
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/c53ef398
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/c53ef398

Branch: refs/heads/master
Commit: c53ef3984ac2f7323f67b762de1395464fcccd66
Parents: 7b10546
Author: Andy Seaborne <andy@apache.org>
Authored: Mon Nov 16 21:08:02 2015 +0000
Committer: Andy Seaborne <andy@apache.org>
Committed: Mon Nov 16 21:33:14 2015 +0000

----------------------------------------------------------------------
 .../main/java/org/apache/jena/sparql/function/CastXSD.java  | 9 ++++-----
 .../test/java/org/apache/jena/sparql/expr/TestCastXSD.java  | 8 ++++++--
 2 files changed, 10 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/c53ef398/jena-arq/src/main/java/org/apache/jena/sparql/function/CastXSD.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/function/CastXSD.java b/jena-arq/src/main/java/org/apache/jena/sparql/function/CastXSD.java
index b3c3837..d5c8103 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/function/CastXSD.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/function/CastXSD.java
@@ -300,17 +300,16 @@ public class CastXSD extends FunctionBase1 implements FunctionFactory
{
 
     // Return the decimal lexical form for a double value.
     // Java big decimal allows "E" forms, XSD does not.
+    // For RDF purposes, return ".0" forms (which are 
+    // short-forms in Turtle and SPARQL).
     private static String doubleToDecimalString(double d) {
         // BigDecimal.valueOf(d) can lead to trailing zeros.
         String lex = BigDecimal.valueOf(d).toPlainString() ;
         // Clean the string. 
         int i = lex.indexOf('.') ;
         if ( i < 0 )
-            return lex ;
-        // Often one or two
-        while(lex.endsWith("00"))
-            lex = lex.substring(0,  lex.length()-2) ;
-        while(lex.endsWith("0"))
+            return lex+".0" ;
+        while((i < lex.length()-2) && lex.endsWith("0"))
             lex = lex.substring(0,  lex.length()-1) ;
         return lex ;
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/c53ef398/jena-arq/src/test/java/org/apache/jena/sparql/expr/TestCastXSD.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/expr/TestCastXSD.java b/jena-arq/src/test/java/org/apache/jena/sparql/expr/TestCastXSD.java
index d382494..85a7042 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/expr/TestCastXSD.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/expr/TestCastXSD.java
@@ -73,8 +73,12 @@ public class TestCastXSD {
     @Test public void cast_to_integer_26()  { testNoCast    ("xsd:byte('500'^^xsd:decimal)")
; }
 
     @Test public void cast_decimal_10()     { testCast      ("xsd:decimal('1e-20'^^xsd:double)",
   "0.00000000000000000001") ; }
-    @Test public void cast_decimal_11()     { testCast      ("xsd:decimal('1e-19'^^xsd:double)",
       "0.0000000000000000001") ; }
-    @Test public void cast_decimal_12()     { testCast      ("xsd:decimal('1e-18'^^xsd:double)",
       "0.000000000000000001") ; }
+    @Test public void cast_decimal_11()     { testCast      ("xsd:decimal('1e-19'^^xsd:double)",
   "0.0000000000000000001") ; }
+    @Test public void cast_decimal_12()     { testCast      ("xsd:decimal('1e-18'^^xsd:double)",
   "0.000000000000000001") ; }
+    @Test public void cast_decimal_13()     { testCast      ("xsd:decimal('1e0'^^xsd:double)",
     "1.0") ; }
+    @Test public void cast_decimal_14()     { testCast      ("xsd:decimal('11e0'^^xsd:double)",
    "11.0") ; }
+    @Test public void cast_decimal_15()     { testCast      ("xsd:decimal('-0.01'^^xsd:double)",
   "-0.01") ; }
+    @Test public void cast_decimal_16()     { testCast      ("xsd:decimal('1'^^xsd:double)",
       "'1.0'^^xsd:decimal") ; }
 
     @Test public void cast_from_string_01() { testCast      ("xsd:integer('+1'^^xsd:string)",
          "'+1'^^xsd:integer") ; }
     @Test public void cast_from_string_02() { testNoCast    ("xsd:integer('a'^^xsd:string)")
; }


Mime
View raw message