I’m reporting this issue on behalf of a user of the Couchbase Lite SDK for Dart I’m maintaining. Here is the original issue: Unwanted single / double precision conversion during replication from CBL to CB server · Issue #557 · cbl-dart/cbl-dart · GitHub
While investigating the problem, I found that the root cause is with the WriteFloat
function in Fleece. It is used as part of JSON encoding and in turn when sending document data as JSON during replication. It appears that some floats are not correctly formatted as strings. 307.79998779296875F
is converted in to "307.8"
.
Adding the following assertion to the WriteFloat
test in NumericTests.cc
results in an assertion failure:
expectDescription("307.79998779296875", 307.79998779296875F);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FleeceTests is a Catch v2.13.8 host application.
Run with -? for options
-----------------------------------------------------------------------------------------------------------------------
WriteFloatDebug
-----------------------------------------------------------------------------------------------------------------------
/Users/terwesten/dev/fleece/Tests/NumericTests.cc:170
.......................................................................................................................
/Users/terwesten/dev/fleece/Tests/NumericTests.cc:171: FAILED:
CHECK( floatStr(307.79998779296875F) == "307.79998779296875" )
with expansion:
"307.8" == "307.79998779296875"
=======================================================================================================================
test cases: 1 | 1 failed
assertions: 2 | 1 passed | 1 failed
NB: NumericTests.cc
is currently not included in the FleeceTests
CMake target.
5 posts - 3 participants