Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-276879

Floats are truncated when cast to longs with /data, all other cases round down

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.21.1, 24w38a
    • Confirmed
    • Commands
    • Low
    • Platform

      Using `data modify storage ...`, you can cast a float or double to a byte, int, or long by appending it to an array of the corresponding type. When doing this, all cases round down, except appending a float to a long array, which truncates the value instead.

      How to reproduce:

      1. Run commands to create byte, int, and long arrays:
        /data modify storage test byte set value [B;]
        /data modify storage test int set value [I;]
        /data modify storage test long set value [L;]
      2. Append a float and a double to each array. Make sure the number is negative and not an integer, so that truncating behaves differently than rounding down.
        /data modify storage test byte append value -1.5f
        /data modify storage test byte append value -1.5d
        
        /data modify storage test int append value -1.5f
        /data modify storage test int append value -1.5d
        
        /data modify storage test long append value -1.5f
        /data modify storage test long append value -1.5d
      3. Get the values of the arrays:
        /data get storage test
      4. You can see that both the byte and int arrays are [-2, -2], while the long array is [-1, -2], meaning that the float got truncated instead of rounded down when cast to a long.

      I would expect that all cases would be consistent, rather than having one combination that behaves differently than all of the others.

            Unassigned Unassigned
            mr_cheese mr_cheese
            Votes:
            4 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              CHK: