0

disclaimer: im using lua on the table top simulator game, I don't know if this interfere in any kind of way with the "regular work" of lua

I already have a bunch of vectors pre-calculated:

    grey_res = {55.00, 3, -10.80},
    commerce = {55.00, 3, -8.10},
    blue = {55.00, 3, -5.40},
    war_conflict = {55.00, 3, -2.70},
    naval_conflict = {55.00, 3, 0},
    compass = {55.00, 3, 2.70},
    tablet = {55.00, 3, 5.40},
    gear = {55.00, 3, 8.10},
    green_island = {55.00, 3, 10.80},

and I manged to find the right formula to calucate these values with origins and offset but here's the lua output

    Vector: { 54.999997, 3, -10.800006}
    Vector: { 54.999997, 3, -8.100005}
    Vector: {54.999996, 3, -5.400006}
    Vector: {54.999995, 3, -2.700005}
    Vector: {54.999995, 3, -0.000005}
    Vector: {54.999995, 3, 2.699995}
    Vector: {54.999994, 3, 5.399996}
    Vector: {54.999994, 3, 8.099996}
    Vector: {54.999994, 3, 10.799996}

As you can see the coordinates kinda matches the one I designed but they are still off and since I need to do other operations with them I'm scared they will mess up my objects's placements Is there a way to fix this?

I was thinking of making my way out of this with if statements but the code will get pretty messy

EDIT: these are just some coordinates examples, in reality all of these values changes for every player at the table, so for some of them the x might be a positive float, for others a negative one and the same goes for the z

  • 3
    Does this answer your question? [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – Nifim May 08 '23 at 22:35
  • 4
    No, this is not a duplicate. It needs debugging details though. Why is this not a duplicate? First of all, small integers like `55` can be represented exactly by floats - even 32 bit ones. There should be *absolutely zero* error there (unless some math is done on the floats, in which case the math could probably be fixed to yield the exact result). Furthermore, Lua typically uses 64-bit floats, which have a *very small* error; however the errors here are *rather large* and at about the sixth decimal point, suggesting some conversion to 32-bit floats is happening. – Luatic May 09 '23 at 07:14
  • 2
    If a Vector uses 32 bit floats it would perfectly match a float with one bit error, rounded for printing. "I manged to find the right formula" does not sound like the exact integer has been input. – Luke100000 May 09 '23 at 08:46
  • 1
    Edit the question to provide a [mre]. – Eric Postpischil May 09 '23 at 11:29
  • 1
    @Nifim: Please do not promiscuously mark floating-point questions as duplicates of that one. The mere fact that a question contains floating-point numbers and has some inaccuracies does not mean it is solely or primarily due to essential floating-point rounding. In this case, it appears some other agent has intervened and/or OP is not showing the necessary context. You should analyze a question sufficiently to ascertain that the problem it asks about is indeed caused by essential floating-point rounding before marking it as a duplicate of that other question. – Eric Postpischil May 09 '23 at 17:54
  • 1
    @EricPostpischil I disagree with your assertion that it was promiscuously and find your comment fairly rude in tone. OP stated "I manged to find the right formula to calucate these values with origins and offset" and then wonders why those values do not match the expected "pre-calculated" values. they also then go on to explain "these are just some coordinates examples, in reality all of these values changes for every player at the table" – Nifim May 09 '23 at 18:01
  • @Nifim: As Luatic noted, this is not a duplicate. The errors shown do not arise from essential rounding of the floating-point type; 55 would not be changed to 54.999997 merely because of the nature of floating-point arithmetic. Voting to close it as a duplicate of that question was indiscriminate. – Eric Postpischil May 09 '23 at 18:04
  • 2
    @EricPostpischil: @Luatic seems to assume that OP entered the literal `55` rather than doing a series of calculation. Based on the text in the post, that is not the conclusion I drew or believe should be drawn. At any rate if the post is closed you will be able to vote reopen it, we also have not yet heard anything back from OP. – Nifim May 09 '23 at 18:07
  • This is not a Lua issue. This is not math issue. This isn't even an issue with the OP's code. This is a known [tag:tabletop-simulator] issue. There is drift in the location of game Objects sometimes. I thought they had fixed that in the latest version? Maybe they haven't released the fix yet. Search [here](https://tabletopsimulator.nolt.io/). There's definitely a ticket about it. @Eric Postpischil – ikegami Jun 08 '23 at 18:58

1 Answers1

0

This is a known issue with Tabletop Simulator.

ikegami
  • 367,544
  • 15
  • 269
  • 518