lua_numbers in NS2

wulf 21wulf 21 Join Date: 2011-05-03 Member: 96875Members
<div class="IPBDescription">single or double?</div>Lately I stumbled over the fact that Vectors in NS2 are only 16 bytes long. Since a lua_number is a double precision float by default (8 bytes) but can be modified before compiling the Lua library, I'm wondering if the devs have actually done that, because a Vector would have to store 3 numbers. (24 bytes if double, 12 bytes if single). Since most data I have to save for my project are numbers, it would almost cut the file size half if I could "savely"(no data loss) save single instead of double precision floats.

Comments

  • playerplayer Join Date: 2010-09-12 Member: 73982Members
    NS2's Lua-VM indeed uses double precision floating-points.
  • wulf 21wulf 21 Join Date: 2011-05-03 Member: 96875Members
    so, why does a Vector only have 16 bytes then?
  • playerplayer Join Date: 2010-09-12 Member: 73982Members
    I don't know what you're doing. Are you measuring the # of bytes allocated for a vector-object (lua_objlen)?
  • wulf 21wulf 21 Join Date: 2011-05-03 Member: 96875Members
    yes. And I can save a Vector in a file and load it later without problems, the file length is exactly 16 bytes.
  • fsfodfsfod uk Join Date: 2004-04-09 Member: 27810Members, NS2 Developer, Constellation, NS2 Playtester, Squad Five Blue, Squad Five Silver, Squad Five Gold, Subnautica Playtester, NS2 Community Developer, Pistachionauts
    the first 4 bytes of the 16 is the userdata typefield Max's luabinding system uses i think
  • playerplayer Join Date: 2010-09-12 Member: 73982Members
    Well I just verified the new Lua-VM still does double precision. The Vector-class however doesn't seem to be able to deal with it properly. Anything above a float (4 bytes), and it starts to behave oddly (botching up values passed to it). My guess is the Vector-class inside the engine only deals with single-precision floats. This combined with fsfod's guess might explain your 16-byte result.
Sign In or Register to comment.