- Security with Go
- John Daniel Leon
- 184字
- 2021-06-30 19:06:47
Other numeric types
Go also provides a complex number for advanced mathematical applications, and a few aliases for conveniences:
- complex64: Complex number with float32 real and imaginary parts
- complex128: Complex number with float64 real and imaginary parts
- byte: Alias for uint8
- rune: Alias for int32
You can define numbers in the decimal, octal, or hexadecimal format. Decimal or base-ten numbers need no prefix. Octal or base-eight numbers should be prefixed with a zero. Hexadecimal or base-sixteen numbers should be prefixed with a zero and an x.
You can read more about the octal numeral system at https://en.wikipedia.org/wiki/Octal, decimal at https://en.wikipedia.org/wiki/Decimal, and hexadecimal at https://en.wikipedia.org/wiki/Hexadecimal.
Note that numbers are stored as integers, and there are no differences between them except for how they are formatted in the source code for the human. Octal and hexadecimal can be useful when working with binary data. Here is a short example of how to define integers:
package main
import "fmt"
func main() {
// Decimal for 15
number0 := 15
// Octal for 15
number1 := 017
// Hexadecimal for 15
number2 := 0x0F
fmt.Println(number0, number1, number2)
}
推薦閱讀
- 線性代數(shù)及其應(yīng)用(原書第6版)
- 好玩的數(shù)學符號
- 開悟:數(shù)學黑客的生活之旅
- 我的第一本趣味數(shù)學書2
- 數(shù)學實驗教程
- 隨機數(shù)學及其應(yīng)用
- Blockchain for Decision Makers
- 數(shù)學多大點事兒
- 高等數(shù)學習題全解(上冊)
- 可視化微分幾何和形式:一部五幕數(shù)學正劇
- 別萊利曼的趣味幾何學
- 數(shù)據(jù)科學與機器學習:數(shù)學與統(tǒng)計方法
- 全局優(yōu)化理論幾種算法的改進研究
- 奇妙的數(shù)學:激發(fā)大腦潛能的經(jīng)典名題(升級版)
- ANSYS 2020有限元分析從入門到精通(升級版)