SQLite module not behaving with negative floats

Started by EK.IceFlake, May 05, 2017, 10:36 AM

Previous topic - Next topic

EK.IceFlake

Well...
was making a custom class system.
skin.position    = Vector3(stmt.GetValue("position_x"), stmt.GetValue("position_y"), stmt.GetValue("position_z"));
And apparently:
print(skin.position);[USR] 0.000000,556.091003,11.098300

DB Browser for SQLite shows the correct value for it (-768.839, 556.091 and 11.0983)

A workaround would be to 5000 + position and then position - 5000, but it's exactly that - a workaround - and I don't like workarounds.

.

The bug comes from the fact that SQLite stores floating point numbers with double precision. However, the squirrel language stores floating point numbers with single precision. So in the function I've used to convert a double floating point number within the limits of a single floating point number. I've used the C++ std::numeric_limits::min() to identify the minimal value that a float can represent. However, the mistake here was that the ::min() has a different behavior on floating point values. Where integral values would return the negative minimal value. Floating point values return 0.0000. Which makes the conversion think that 0.0 is the lowest value a float can represent. Which obviously is not the desired behavior. The function that has the intended behavior is std::numeric_limits::lowest(). And this minor detail is what caused the issue.

The bug was fixed locally along with a few other bugs caught by the static analyzer from a newer version of GCC. I've also updated the SQLite library to the latest version available for more performance and stability. Binaries and everything should be available soon.
.

.

Code changes and binaries are now available. I haven't done too much testing so let's hope everything works correctly.
.

EK.IceFlake

#3
Code 193 on the new plugin.
:edit: Forgot to use the standalone version. Works.
:edit: Floats work perfectly now, good job.