Skip to content

Commit

Permalink
Add PackedByteArray docs warning about s64 int autocasting in GDScript
Browse files Browse the repository at this point in the history
  • Loading branch information
Vocco committed Feb 5, 2025
1 parent a63a8b4 commit cdc8ea7
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/classes/PackedByteArray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@
<param index="0" name="byte_offset" type="int" />
<description>
Decodes a 64-bit unsigned integer number from the bytes starting at [param byte_offset]. Fails if the byte count is insufficient. Returns [code]0[/code] if a valid number can't be decoded.
[b]Warning:[/b] Since GDScript's [int] is a 64-bit signed integer, the result will be automatically cast to a signed value when ran in GDSCript. Unsigned 64-bit integers can represent numbers in the range [code][0, 2^64 - 1][/code], whereas signed ones can represent numbers in the range [code][-(2^63), 2^63 - 1][/code]. This means:
- For values between [code]0[/code] and [code]2^63 - 1[/code], the decoded number will appear as the expected positive integer.
- For values above [code]2^63 -1[/code], the decoded number will "wrap around" and be represented as a negative number. (For example, [code]2^64[/code] will become [code]-(2^63)[/code].)
</description>
</method>
<method name="decode_var" qualifiers="const">
Expand Down

0 comments on commit cdc8ea7

Please sign in to comment.