When using /compute in integer mode, arithmetic works correctly once the values have been loaded. However, the initial values are incorrectly converted from floating-point numbers to integers.
This affects both constants and scoreboard values. Large values can lose precision during this initial conversion because 32-bit floating-point numbers cannot represent every integer exactly above 2^24.
Steps to reproduce
Run following commands:
/scoreboard objectives add test dummy /scoreboard players set @s test 2000000064 /compute default {type:"minecraft:score",target:"this",score:"test"} integerThe number provider returns
2000000000instead of the expected value2000000064.
Expected behaviour
In integer mode, initial values should be read directly as integers rather than being converted to a float first.
A scoreboard value such as 2000000064 should therefore remain exactly 2000000064.
Attachments
Comments 2
This affects both constant and scoreboard values.
Command to reproduce the constant part:/compute default {type: constant, value: 16777217} integer
Expected output: 16777217
Observed output: 16777216
Code analysis of constant
The codecs defined in ConstantValue uses Codec.FLOAT.
The precision loss happens when parsing the number provider.
This is the root cause of MC-254370. It makes IntRange unable to get the correct range despite using integer mode to resolve the numbers.
Code analysis of score
ScoreboardValue doesn’t implement its own getInt() method.
The default getInt() defined in NumberProvider returns Math.round(this.getFloat(context)), which is essentially rounding the lossy value resolved in float mode.
Thank you for helping us improve Minecraft! We saved your files: