Mojira Archive
MC-276879

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

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.

Unresolved

mr_cheese

2024-09-20, 06:17 PM

2025-01-11, 02:34 AM

5

3

Confirmed

Low

Platform

Commands

Commands

1.21.1, 24w38a

-