C++ for Game Developers: The perils of unsigned math

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 มี.ค. 2024
  • #gamedev #gamedevelopment #programming
    playlist: • C++ for Game Developers
    Discord: / discord
    Patreon: patreon.com/user?u=58955910

ความคิดเห็น • 4

  • @CodAv123
    @CodAv123 2 หลายเดือนก่อน

    These "large" numbers, especially the result of the modulo operator, aren't actually messed up. It's simply how signed integers are represented in binary: the most significant bit (31 in these examples) is set if the number is negative, and the remaining bytes are the two's complement of the negative value, e.g. the less bits are set, the more "negative" the number gets. Static casting such a large unsigned value to its signed counterpart will give the proper result.
    Working on assembly level, it's way clearer to see, because the CPU itself doesn't concern itself with signed or unsigned types at all. It'll just do the binary math, and set flags (negative, carry and overflow) according to the result (based on bits set in the input and output values) of an add/subtract operation. The compiler then generates the code in accordance to the declarations in the C/C++ code and interprets it as such.

  • @SkyFly19853
    @SkyFly19853 2 หลายเดือนก่อน

    Oh...
    back to the memories when I was traumatized by C++ at Computer Science Class at College...
    before stopping this disaster by Python...
    😏

  • @10bokaj
    @10bokaj 2 หลายเดือนก่อน +1

    use odin instead. It fixes this.

  • @Kapendev
    @Kapendev 2 หลายเดือนก่อน

    Not a problem in Ada I think. Gamedev in Ada again? 😅