From 529dc61a4e9ec0942660e672df13bdc91221bbec Mon Sep 17 00:00:00 2001 From: tsingbx Date: Tue, 12 Dec 2023 13:05:50 +0800 Subject: [PATCH 1/5] add doc for integers --- 107-Integers/integers.gop | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/107-Integers/integers.gop b/107-Integers/integers.gop index 8b13789..6dd4525 100644 --- a/107-Integers/integers.gop +++ b/107-Integers/integers.gop @@ -1 +1,18 @@ +// 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, and +// int64, 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, and uint64, but +// the uint type should be used unless you need a specific size. +// +// int Literal Values +// Gop values can be expressed literally, where the value is defined directly in the source code file. Common +// uses for literal values include operands in expressions and arguments to functions, as shown following: +println 20+20 +println 20+30 + +// int 20, Values can also be expressed in hex (0x14), octal (0o24), and binary notation (0b0010100). +// unit There are no uint literals. All literal whole numbers are treated as int values. From 187b5f675be2bb90022c9ae7c13f68ee6557c442 Mon Sep 17 00:00:00 2001 From: tsingbx Date: Tue, 12 Dec 2023 13:34:33 +0800 Subject: [PATCH 2/5] modify doc for integers --- 107-Integers/integers.gop | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/107-Integers/integers.gop b/107-Integers/integers.gop index 6dd4525..70fc6e0 100644 --- a/107-Integers/integers.gop +++ b/107-Integers/integers.gop @@ -7,12 +7,19 @@ // types that have a specific size, such as uint8, uint16, uint32, and uint64, but // the uint type should be used unless you need a specific size. // -// int Literal Values -// Gop values can be expressed literally, where the value is defined directly in the source code file. Common -// uses for literal values include operands in expressions and arguments to functions, as shown following: +// 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: + +num := 1_000_000 //Go+ support, same as 1000000 +println num println 20+20 println 20+30 +println 0x14 //in hex +println 0o24 //in octal +println 0b0010100 // binary -// int 20, Values can also be expressed in hex (0x14), octal (0o24), and binary notation (0b0010100). -// unit There are no uint literals. All literal whole numbers are treated as int values. +c := int128(12345) // If you want a different type of integer, you can use casting. +println c From da327e460fc4a3ea62a89e0d4f64657b4909e0bd Mon Sep 17 00:00:00 2001 From: tsingbx Date: Tue, 12 Dec 2023 13:39:10 +0800 Subject: [PATCH 3/5] add int128,uint128 sample --- 107-Integers/integers.gop | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/107-Integers/integers.gop b/107-Integers/integers.gop index 70fc6e0..4b22498 100644 --- a/107-Integers/integers.gop +++ b/107-Integers/integers.gop @@ -1,10 +1,10 @@ // 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, and +// also integer types that have a specific size, such as int8, int16, int32, int64, int128, and // int64, 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, and uint64, but +// types that have a specific size, such as uint8, uint16, uint32, uint64, 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). @@ -23,3 +23,6 @@ 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) From 6eaf468f961039fe8add10186a55f2d2754f072e Mon Sep 17 00:00:00 2001 From: tsingbx Date: Tue, 12 Dec 2023 13:41:43 +0800 Subject: [PATCH 4/5] empty --- 107-Integers/integers.gop | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/107-Integers/integers.gop b/107-Integers/integers.gop index 4b22498..cdf9412 100644 --- a/107-Integers/integers.gop +++ b/107-Integers/integers.gop @@ -1,10 +1,10 @@ // 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, int128, and -// int64, but the int type should be used unless you need a specific size. +// 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, uint128, but +// 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). From 3bb2bf8f8933500e26f146c67450fafc38871640 Mon Sep 17 00:00:00 2001 From: tsingbx Date: Tue, 12 Dec 2023 16:03:34 +0800 Subject: [PATCH 5/5] add cast bool --- 107-Integers/integers.gop | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/107-Integers/integers.gop b/107-Integers/integers.gop index cdf9412..20a559e 100644 --- a/107-Integers/integers.gop +++ b/107-Integers/integers.gop @@ -10,11 +10,16 @@ // 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: +// 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