Skip to content

Commit 72fedb0

Browse files
authored
Merge pull request #64 from tsingbx/integers
add doc for integers
2 parents 37f0c49 + 3bb2bf8 commit 72fedb0

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

107-Integers/integers.gop

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1+
// int type represents a whole number, which can be positive or negative. The
2+
// int type size is platform-dependent and will be either 32 or 64 bits. There are
3+
// also integer types that have a specific size, such as int8, int16, int32, int64, and
4+
// int128, but the int type should be used unless you need a specific size.
5+
//
6+
// 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
7+
// types that have a specific size, such as uint8, uint16, uint32, uint64 and uint128, but
8+
// the uint type should be used unless you need a specific size.
9+
//
10+
// For int 20 values can also be expressed in hex (0x14), octal (0o24), and binary notation (0b0010100).
11+
// uint, there are no uint literals. All literal whole numbers are treated as int values.
12+
//
13+
// Go+ also supports writing numbers with _ as separator and also support cast bool to number types.
14+
// As example shows
115

16+
num := 1_000_000 //Go+ support, same as 1000000
17+
println num
18+
19+
println int(true) //Go+ support cast bool to int
20+
println float64(true) //and to float64
21+
println complex64(true) //and to complex64, and so on.
22+
23+
println 20+20
24+
println 20+30
25+
println 0x14 //in hex
26+
println 0o24 //in octal
27+
println 0b0010100 // binary
28+
29+
c := int128(12345) // If you want a different type of integer, you can use casting.
30+
println c
31+
32+
u128 := uint128(12345)
33+
println(u128)

0 commit comments

Comments
 (0)