Representation of float values in a list #790
-
I am working with a list of floats and value like 2.4 is being converted to 2.4000000953674316 etc. Here is the code I am using uri "http://sadl.org/test.sadl" alias test. Object is a class Rule MinValue obj1 is a Object Ask: "select * where {?x ?y ?z} limit 1". The output in the console is as follows Inference of 'C:\Sadl3Workspace21\TestList\Test.sadl' requested. Is there some way I can preserve 2.4 value as is? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 6 replies
-
The "list" built-in function converts floats to doubles. I don't remember why this is done, but I think there's a reason. The conversion uses the java.lang.Float class: |
Beta Was this translation helpful? Give feedback.
-
That helped; I used double instead of float and that keeps 2.4 as 2.4. |
Beta Was this translation helpful? Give feedback.
-
@AbhaMoitra , I think that the relevant history of List.java is in openge. It was part of the proprietary Jena reasoner for GE before being moved to SADL 3 on github. I don't have access to that repo. It would have been in the project for that reasoner I think. If you want to look and see if you can find the history that might be helpful in terms of understanding why it is implemented as it is. Or we could have a Teams meeting and I could help you find the relevant history. If it's worth it to you. |
Beta Was this translation helpful? Give feedback.
-
@AbhaMoitra , this conversion of float to double is a pattern across many built-ins. There is a reason, but it escapes me. Unless you wish to pursue it I think we will not investigate further at this time and leave it as is. |
Beta Was this translation helpful? Give feedback.
The "list" built-in function converts floats to doubles. I don't remember why this is done, but I think there's a reason. The conversion uses the java.lang.Float class:
'''((Float)v).doubleValue()'''
For the float 2.4, this returns the value "2.4000000953674316".