当前位置:网站首页>Go learning notes (3) basic types and statements (2)

Go learning notes (3) basic types and statements (2)

2022-07-06 07:53:00 Raring_ Ringtail

 Insert picture description here

Take the book back , I cleaned it up yesterday go In words , Let's sort it out today go Boolean and numeric types in the basic types of .

Boolean (Booleans) type

bool There's nothing to say about type , It's only worth two true and false, Its zero value is false.

var flag bool //  If there is no assignment, it will be set to zero false
var isBeautiful = true

value type

go Yes 12 Different numerical types , They fall into three categories : integer 、 floating-point 、 The plural .go The value type of is not like c In that language charshortintlongfloatdouble This type of numeric value related to the number of bits in the operating system .

For integer types , It is used uniformly int Represents and marks its digits after . The following table :

Type name Value range
int8-128 to 127
int16–32768 to 32767
int32–2147483648 to 2147483647
int64–9223372036854775808 to 9223372036854775807
uint80 to 255
uint160 to 65536
uint320 to 4294967295
uint640 to 18446744073709551615

For floating point types , It USES float32 and float64 Express 32 Bit and 64 Bit floating point . The following table :

Type name Maximum absolute value Minimum non-zero absolute value
float323.40282346638528859811704183484516925440e+381.401298464324817070923729583289916131280e-45
float641.797693134862315708145274237317043567981e+3084.940656458412465441765687928682213723651e-324
Several special integer types

byte yes uint8 Alias , The two are completely equivalent .

int stay 32 Bit system is int32 stay 64 Bit system is int64, So when int And int32 or int64 There will be compilation errors in the assignment comparison or mathematical calculation of variables of .go Language does not support implicit type conversion between variables , This is also what I like very much go A point of language ,go Many grammatical and semantic mistakes are directly prohibited , Although not so convenient , But it makes the code clearer .

uint And int Similar is just non negative .

The default value of the whole number is int type .

rune and uintptr It is also two special integer types , I'll introduce them later .

operation

go The numerical operation of is similar to that of other languages .

Integers cannot be divided by 0, Floating point division 0 You'll get +Inf and -Inf, And floating point 0 except 0 You'll get NaN.

The comparison of floating-point numbers is imprecise .

Plural type

I didn't know it until today go There are plural types , Namely complex64 and complex128.

I feel that this type may never be used , Don't learn it .


Welcome to my WeChat official account. Notes on Jiangda

原网站

版权声明
本文为[Raring_ Ringtail]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131851005041.html