mojira.dev
MC-311428

Number providers lose precision when reading the initial values in integer mode

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

  1. Run following commands:

    /scoreboard objectives add test dummy
    /scoreboard players set @s test 2000000064
    /compute default {type:"minecraft:score",target:"this",score:"test"} integer
  2. The number provider returns 2000000000 instead of the expected value 2000000064.

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

Thank you for helping us improve Minecraft! We saved your files:

[media]

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.

CJDev

(Unassigned)

Confirmed

Platform HC

Low

Commands

26.3 Snapshot 10

26.3 Pre-Release 1

Retrieved