စံကား

03Values and kinds

Integers

Whole numbers, their sizes, and signed versus unsigned.

An integer is a whole number with no fraction: ၀, ၇, ၁၀၀၀, -၅. Its kind is ကိန်းပြည့် ("whole number").

The computer stores each integer in a fixed number of bits (base-2 digits). More bits hold bigger numbers. A program can choose the size, and whether negative numbers are allowed.

စံကား

Expected output

၄၂
၁၂၇
၂၅၅
၂၁၄၇၄၈၃၆၄၇
-၅

Writing a kind before the digits, as in ၈ ဘစ် ကိန်းပြည့် ၁၂၇, fixes the kind of that number. Without one, an integer has the default kind ကိန်းပြည့်.

Building an integer kind

An integer kind is made of up to three parts, in this order:

PartWordsMeaning
sign (optional)လက္ခဏာရှိ / လက္ခဏာမဲ့"with sign" (can be negative) / "without sign" (zero or more)
size (optional)၈ ဘစ်, ၁၆ ဘစ်, ၃၂ ဘစ်, ၆၄ ဘစ်, ၁၂၈ ဘစ်8, 16, 32, 64 or 128 bits
kindကိန်းပြည့်integer

Leave out the sign and the integer is signed. Leave out the size and it uses the platform size, which is 64 bits unless the program runs with a different --platform-bits setting.

KindSmallestLargest
၈ ဘစ် ကိန်းပြည့်-128127
လက္ခဏာမဲ့ ၈ ဘစ် ကိန်းပြည့်0255
၁၆ ဘစ် ကိန်းပြည့်-32,76832,767
လက္ခဏာမဲ့ ၁၆ ဘစ် ကိန်းပြည့်065,535
၃၂ ဘစ် ကိန်းပြည့်about -2.1 billionabout 2.1 billion
၆၄ ဘစ် ကိန်းပြည့်about -9.2 × 10¹⁸about 9.2 × 10¹⁸
ကိန်းပြည့်(64 bits unless set otherwise)

When in doubt, use plain ကိန်းပြည့်.

A number that does not fit

If a number is too big for its kind, the program does not run:

စံကားZK0220

Expected error

error[ZK0220]: literal ၂၅၆ does not fit its kind

Hands on

  • Print the largest လက္ခဏာမဲ့ ၁၆ ဘစ် ကိန်းပြည့်, then test one more than it.
  • Can a လက္ခဏာမဲ့ integer hold -၁? Test it.

Next: Writing integers.