Recently and the server colleague to deal with a game data problem, found that the server Lua script floating point data in the server C + + code is called the error may occur. Similarly, if the client uses Lua's built-in library of functions to manipulate floating-point numbers, such rounding errors are reproduced, with a simple example:
Local k = 1+122/100;
Local T = 250*k
Print ("T:", T)
Print ("Math t:", Math.floor (t))
Print (String.Format ("string t:%d", T))
Ideally T, Math T, and string T are all 555.
The actual output only T is 555,math T and string T are both 554.
So the client and server in the same set of calculation formula to calculate a game data, because the client is a pure script operation to get results, the server is the script operation of the intermediate result T in C + + code to continue processing, the middle of the accuracy error problem, The result of the client and server always has a slight numerical bias.
Specific accuracy error reasons if the reader knows, welcome to popular science bloggers.
A precision error problem for LUA and C + +