Page 1 of 1

[1.1.91] --dump-data outputs some values with an excesive number of decimal places

Posted: Sat Oct 07, 2023 11:16 pm
by calloatti
The output of --dump-data for some values has an excesive number of decimal places. Examples:

Code: Select all

  clickable_label = {
    type = "label_style",
    hovered_font_color = { 1, 0.74000000000000003552713678800500929355621337890625, 0.4 },
    clicked_font_color = {
      ["r"] = 0.9800000000000000710542735760100185871124267578125,
      ["g"] = 0.660000000000000053290705182007513940334320068359375,
      ["b"] = 0.220000000000000017763568394002504646778106689453125
    }

Code: Select all

game_controller_hovered_font_color = { 1, 0.6800000000000000710542735760100185871124267578125, 0 },

Code: Select all

  {
    "filename": "__base__/sound/metallic-chest-open.ogg",
    "volume": 0.429999999999999982236431605997495353221893310546875
  },

Code: Select all

collision_box = { { -1.19999999999999996447286321199499070644378662109375, -1.19999999999999996447286321199499070644378662109375 }, { 1.19999999999999996447286321199499070644378662109375, 1.19999999999999996447286321199499070644378662109375 } },
While technically not a bug, this looks kind of silly.

Re: [1.1.91] --dump-data outputs some values with an excesive number of decimal places

Posted: Sat Oct 07, 2023 11:30 pm
by Rseding91
Thanks for the report however I don't consider this broken. The values are what they are and are largely meant for machine processing not human reading.

Re: [1.1.91] --dump-data outputs some values with an excesive number of decimal places

Posted: Sun Oct 08, 2023 12:13 am
by calloatti
After cheking the data, for example if "assembling-machine-3" has a defined collision box in \data\base\prototypes\entity\entities.lua as:

Code: Select all

collision_box = {{-1.2, -1.2}, {1.2, 1.2}},
And the output in data-raw-dump.json is:

Code: Select all

  "collision_box": 
  [
    [
      -1.19999999999999996447286321199499070644378662109375,
      -1.19999999999999996447286321199499070644378662109375
    ],
    [
      1.19999999999999996447286321199499070644378662109375,
      1.19999999999999996447286321199499070644378662109375
    ]
  ],
I would say that something is not right, there is a round-off error introduced somewhere. I would expect that the output should be the same as the input as in:

Code: Select all

  "collision_box": 
  [
    [
      -1.2,
      -1.2
    ],
    [
      1.2,
      1.2
    ]
  ],

Re: [1.1.91] --dump-data outputs some values with an excesive number of decimal places

Posted: Sun Oct 08, 2023 12:18 am
by Silari
They are floating point values. There is going to be some slight drift because you can't store those exact values in a float, only a very close approximation. Anything that rounds it to a couple of decimal places is going to get the original value back in almost every case.

Re: [1.1.91] --dump-data outputs some values with an excesive number of decimal places

Posted: Sun Oct 08, 2023 1:53 am
by calloatti
They are floating point values. There is going to be some slight drift because you can't store those exact values in a float, only a very close approximation. Anything that rounds it to a couple of decimal places is going to get the original value back in almost every case.
Yes, I understand that, I just changed the code I use to convert the json output to lua and added logic to fix the issue. Thanks.