Uploaded image for project: 'Apache Jena'
  1. Apache Jena
  2. JENA-1943

Increase Precision of Decimal Calculation Results

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • Jena 3.14.0, Jena 3.16.0
    • Jena 3.17.0
    • ARQ
    • None

    Description

      The precision of calculation results with type xsd:decimal is limited without need.

      An Example:

      import org.apache.jena.query.QueryExecutionFactory;
      import org.apache.jena.rdf.model.ModelFactory;
      import org.junit.jupiter.api.Test;
      
      public class MaxDecimalDivissionPrecissionTest {
      
      	@Test
      	public void maxDecimalDivissionPrecission() {
      		String query = "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> "//
      				+ "SELECT"//
      				+ "  (     STR(1/STRDT(\"1000000000000000000000000\", xsd:decimal)) AS ?times10)"//
      				+ "  (     STR(1/STRDT(\"10000000000000000000000000\", xsd:decimal)) AS ?calculated)"//
      				+ "  (DATATYPE(1/STRDT(\"10000000000000000000000000\", xsd:decimal)) AS ?type)"//
      				+ "  (     STR(  STRDT(\"0.0000000000000000000000001\", xsd:decimal)) AS ?direct)"//
      				+ "  (     STR(1/STRDT(\"0.0000000000000000000000000000000000000000000001\", xsd:decimal)) AS ?large)"//
      				+ "WHERE {}";
      		System.out.println(QueryExecutionFactory.create(query, ModelFactory.createDefaultModel()).execSelect().next().toString().replace(" (", "\n("));
      	}
      }
      

      Output:

      ( ?times10 = "0.000000000000000000000001" )
      ( ?direct = "0.0000000000000000000000001" )
      ( ?calculated = "0.0" )
      ( ?large = "10000000000000000000000000000000000000000000000.0" )
      ( ?type = xsd:decimal )
      

       
      I would expect ?calculated == ?direct. This only affects very small numbers, very large numbers are not affected. I also checked Wikibase and RDF4J and did not find this limitation. Please consider to remove this limitation as I need higher precision in a view cases in a project.

      Attachments

        Activity

          People

            andy Andy Seaborne
            jmkeil Jan Martin Keil
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 20m
                20m