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

Bugs that are actually features.
Post Reply
calloatti
Manual Inserter
Manual Inserter
Posts: 3
Joined: Thu Sep 21, 2023 1:26 pm
Contact:

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

Post 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.
Attachments
factorio-current.log
(6.35 KiB) Downloaded 24 times
Last edited by calloatti on Sat Oct 07, 2023 11:53 pm, edited 1 time in total.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13218
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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.
If you want to get ahold of me I'm almost always on Discord.

calloatti
Manual Inserter
Manual Inserter
Posts: 3
Joined: Thu Sep 21, 2023 1:26 pm
Contact:

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

Post 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
    ]
  ],

User avatar
Silari
Filter Inserter
Filter Inserter
Posts: 490
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

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

Post 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.

calloatti
Manual Inserter
Manual Inserter
Posts: 3
Joined: Thu Sep 21, 2023 1:26 pm
Contact:

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

Post 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.

Post Reply

Return to “Not a bug”