1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Crystal: 64ビット整数や符号なし整数を定義したい

Posted at

Crystalには4つの整数型があります: Int8, Int16, Int32, Int64
それぞれ8, 16, 32, 64ビットの数を表現することができます。
また、4種類の符号なし整数型があります: UInt8, UInt16, UInt32, UInt64

puts 1.class      # Int32

puts 1_i8.class   # Int8
puts 1_i16.class  # Int16
puts 1_i32.class  # Int32
puts 1_i64.class  # Int64

puts 1_u8.class   # UInt8
puts 1_u16.class  # UInt16
puts 1_u32.class  # UInt32
puts 1_u64.class  # UInt64

puts +10    # Int32
puts -20    # Int32

puts 2147483648.class          # Int64
puts 9223372036854775808.class # UInt64

ちなみに、アンダースコアをつけることで、整数の可読性が上がります。

puts 1_000_000 # better than 1000000
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?