Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Cloud by

I have an attribute of type :db.type/float in my Datomic Cloud (solo) instance. When I query for that value, however, I get values of type java.lang.Double. (I actually have 6 float attributes and they all behave this way.)

Is this a bug? I can't see anything in the documentation that describes this behavior. In fact, the schema reference seems to specifically say that it should be float value and not a double.

This is not a big problem, but it is an annoyance because the values I'm transacting as floats are getting extra (noisy) precision added to them, so that e.g. when the user enters a 3.7, it actually shows up as 3.700000047683716. This isn't difficult to fix by casting to float, but it was surprising.

I only see this behavior in Datomic Cloud, by the way. Using dev-local correctly shows the value as a float.

Here's some relevant exchanges from a REPL session demonstrating the issue:

user> (d/q '[:find ?attr-type ?value :where
             [71587003061240196 :student/gpa-weighted-9 ?value]
             [:student/gpa-weighted-9 :db/valueType ?t]
             [?t :db/ident ?attr-type]]
           (d/db conn))
[[:db.type/float 3.700000047683716]]
user> (type (-> *1 first second))
user> (float 3.700000047683716)

1 Answer

0 votes

datomic cloud serialize¹ the communication between the client and the datomic server.

the serialization is done via edn² and the "3.7" value is readed as java.lang.Double by the edn-reader

¹when using in "ions" mode, everything works in memory. Not sure if it will be Float or Double in this case
²maybe transit

Welcome to the Datomic Knowledgebase, where you can make features requests, ask questions and receive answers from other members of the community.