SQLite module not behaving with negative floats

EK.IceFlake

  • Hero Member
  • "We are the champions my fellahs" - Sufyan/VK.SuFy
  • Posts: 1,761
SQLite module not behaving with negative floats
« on May 5th, 2017, 11:36 AM »Last edited on May 5th, 2017, 11:39 AM
Well...
was making a custom class system.
Code: [Select]
skin.position    = Vector3(stmt.GetValue("position_x"), stmt.GetValue("position_y"), stmt.GetValue("position_z"));

And apparently:
Code: [Select]
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.

.

  • VC:MP Beta Tester
  • .
  • Posts: 1,804
Re: SQLite module not behaving with negative floats
« Reply #1, on May 5th, 2017, 06:05 PM »Last edited on May 5th, 2017, 06:58 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() 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.
.

EK.IceFlake

  • Hero Member
  • "We are the champions my fellahs" - Sufyan/VK.SuFy
  • Posts: 1,761
Re: SQLite module not behaving with negative floats
« Reply #3, on May 6th, 2017, 04:35 AM »Last edited on May 6th, 2017, 04:53 AM
Code 193 on the new plugin.
:edit: Forgot to use the standalone version. Works.
:edit: Floats work perfectly now, good job.