SpongePowered/math

Loss of precision of integers

Closed this issue · 0 comments

@Override
public Vector3d toDouble() {
return new Vector3d(this.x, this.y, this.z);
}

This method calls a constructor that takes a float, which causes some numbers such as 29,999,999 to become 30,000,000.
Test code that reproduces the bug:

Vector3i blockPosition = Vector3i.from(29999999, 0, 0);

System.out.println(blockPosition);
System.out.println(blockPosition.toDouble().toInt());

Output:

(29999999, 0, 0)
(30000000, 0, 0)