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:
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;]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.5dGet the values of the arrays:
/data get storage testYou 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.
Linked issues
relates to 1
Attachments
Comments 3
brief code analysis: FloatTag.getAsLong does not call floor in the conversion, as opposed to getAsByte, getAsShort, getAsInt, and DoubleTag.getAsLong which all do. that is the cause of the inconsistent behavior
Can confirm in 1.21.4.