• bool, string
  • (u)int, (u)int8, (u)int16, (u)int32, (u)int64, uintptr(指针)
  • byte, rune
  • float32, float64, complex64, complex128

复数回顾

  • i = √-1
  • 复数:3 + 4i
  • |3 + 4i| = √3² + 4 ² =5
  • i² = -1 , i³ = -i , iⁿ = 1 , ...
  • e^iπ = cosπ + isinπ
  • |e^iπ = √cos²π + √sin²π =1
  • eº =1 , e^i½π = i
  • e^iπ = -1, e^i½3π = -i , e^i2π = 1

最美公式 -- 欧拉公式

  • e^iπ + 1 = 0
func euler(){
var c = 3 + 4i
fmt.Println(cmplx.Abs(c))
fmt.Printf("%.3f\n",cmplx.Pow(math.E,1i * math.Pi) + 1)
fmt.Printf("%.3f\n",cmplx.Exp(1i * math.Pi) + 1)
}

强制类型转换

  • 类型转换是强制的
  • var a, b int = 3, 4
  • var c int = math.Sqrt(a*a + b*b) ✘
  • var c int = int(math.Sqrt(float64(a*a + b*b))) ?