godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.47k stars 20.26k forks source link

GDScript debugger shows incorrect values for very large positive and negative integers #94686

Open jadoc opened 2 months ago

jadoc commented 2 months ago

Tested versions

System information

Godot v4.2.2.stable - Windows 10.0.22631 - Vulkan (Forward+) - dedicated AMD Radeon RX 6900 XT (Advanced Micro Devices, Inc.; 32.0.11021.1011) - 12th Gen Intel(R) Core(TM) i7-12700K (20 Threads)

Issue description

When displaying the values of integers, the GDScript debugger will show incorrect values when the integer is greater than 9223372036854775800 or less than -9223372036854775800. Indeed, the debugger will simply limit itself to those two values when the threshold is exceeded.

Integers in GDScript are documented to support values between -9223372036854775808 and 9223372036854775807. The behavior of GDScript itself appears to be correct, as printing integers containing those maximum and minimum values produces the correct output.

Steps to reproduce

In the following function, insert a breakpoint before the first print() statement. Run the script in debug mode, and examine the values of very_large and very_negative in the debugger. Compare what's displayed in the debugger to the output produced by the print() statements.

func _ready():
    var very_large = 9223372036854775807
    var very_negative = -9223372036854775808
    print(very_large)
    print(very_negative)

Minimal reproduction project (MRP)

large-int-repro.zip

AThousandShips commented 2 months ago

The output is represented in double precision floating point values, which have a limited number of digits of precision (53 bits, which is around 15-17 decimal digits, meaning that the largest integer that can be represented exactly is 9007199254740992)

Probably a duplicate of:

jadoc commented 1 month ago

If anything, this is a duplicate of #32106, which was erroneously labeled as "enhancement".

I have proposed a fix in #95349. PTAL

jadoc commented 1 month ago

At the advice of @AThousandShips, I'm breaking up my pull request into smaller, easier to review chunks. I'm starting with the creating unit tests to capture the existing Range functionally in #95884.