Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
Jena 3.14.0, Jena 3.16.0
-
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.