When to use different integer types?

前端 未结 8 1193
猫巷女王i
猫巷女王i 2021-02-13 20:54

Programming languages (e.g. c, c++, and java) usually have several types for integer arithmetic:

  • signed and unsigned types
  • types
8条回答
  •  梦毁少年i
    2021-02-13 21:20

    You should also consider using unbounded integers and naturals, for when you want to model numbers properly without worrying about overflow.

    Libraries such as GMP and OpenSSL provide "big nums" that support arbitrarily large results -- which is usually the safest thing, unless you can prove the results of your computations are within bounds.

    Additionally, many languages default to unbounded integer types because they are safer.

提交回复
热议问题