Skip to content

Commit

Permalink
Merge pull request #64 from tsingbx/integers
Browse files Browse the repository at this point in the history
add doc for integers
  • Loading branch information
xushiwei authored Feb 12, 2024
2 parents 37f0c49 + 3bb2bf8 commit 72fedb0
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions 107-Integers/integers.gop
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
// int type represents a whole number, which can be positive or negative. The
// int type size is platform-dependent and will be either 32 or 64 bits. There are
// also integer types that have a specific size, such as int8, int16, int32, int64, and
// int128, but the int type should be used unless you need a specific size.
//
// uint type represents a positive whole number. The uint type size is platformdependent and will be either 32 or 64 bits. There are also unsigned integer
// types that have a specific size, such as uint8, uint16, uint32, uint64 and uint128, but
// the uint type should be used unless you need a specific size.
//
// For int 20 values can also be expressed in hex (0x14), octal (0o24), and binary notation (0b0010100).
// uint, there are no uint literals. All literal whole numbers are treated as int values.
//
// Go+ also supports writing numbers with _ as separator and also support cast bool to number types.
// As example shows

num := 1_000_000 //Go+ support, same as 1000000
println num

println int(true) //Go+ support cast bool to int
println float64(true) //and to float64
println complex64(true) //and to complex64, and so on.

println 20+20
println 20+30
println 0x14 //in hex
println 0o24 //in octal
println 0b0010100 // binary

c := int128(12345) // If you want a different type of integer, you can use casting.
println c

u128 := uint128(12345)
println(u128)

0 comments on commit 72fedb0

Please sign in to comment.