Vice City: Multiplayer

Community Projects => SLC's Squirrel Plugin => Bug Reports => Topic started by: EK.IceFlake on May 05, 2017, 10:36 AM

Title: SQLite module not behaving with negative floats
Post by: EK.IceFlake on May 05, 2017, 10:36 AM
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.
Title: Re: SQLite module not behaving with negative floats
Post by: . on May 05, 2017, 05:05 PM
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() (http://en.cppreference.com/w/cpp/types/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() (http://en.cppreference.com/w/cpp/types/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.
Title: Re: SQLite module not behaving with negative floats
Post by: . on May 05, 2017, 05:47 PM
Code changes and binaries are now available. I haven't done too much testing so let's hope everything works correctly.
Title: Re: SQLite module not behaving with negative floats
Post by: EK.IceFlake on May 06, 2017, 03:35 AM
Code 193 on the new plugin.
:edit: Forgot to use the standalone version. Works.
:edit: Floats work perfectly now, good job.