mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 00:11:36 +08:00
格式化4.3章中代码格式 (#736)
This commit is contained in:
@@ -12,7 +12,7 @@ const Pi = 3.14159
|
||||
|
||||
在 Go 语言中,你可以省略类型说明符 `[type]`,因为编译器可以根据变量的值来推断其类型。
|
||||
|
||||
- 显式类型定义: `const b string = "abc"`
|
||||
- 显式类型定义: `const b string = "abc"`
|
||||
- 隐式类型定义: `const b = "abc"`
|
||||
|
||||
一个没有指定类型的常量被使用时,会根据其使用环境而推断出它所需要具备的类型。换句话说,未定义类型的常量会在必要时刻根据上下文来获得相关类型。
|
||||
@@ -32,9 +32,9 @@ f(n + 5) // 无类型的数字型常量 “5” 它的类型在这里变成了 i
|
||||
数字型的常量是没有大小和符号的,并且可以使用任何精度而不会导致溢出:
|
||||
|
||||
```go
|
||||
const Ln2= 0.693147180559945309417232121458\
|
||||
const Ln2 = 0.693147180559945309417232121458\
|
||||
176568075500134360255254120680009
|
||||
const Log2E= 1/Ln2 // this is a precise reciprocal
|
||||
const Log2E = 1/Ln2 // this is a precise reciprocal
|
||||
const Billion = 1e9 // float constant
|
||||
const hardEight = (1 << 100) >> 97
|
||||
```
|
||||
|
Reference in New Issue
Block a user