// 第 1 周 – Go 中的基本数据类型
// 运行（在 go 文件夹中）：go run ./w01/types
package main

import (
	"fmt"
	"math"
	"unsafe"
)

// 常量：它们的值在编译时已知，并且不能改变。
const (
	Pi         = 3.14159
	DaysInWeek = 7
)

func main() {
	// --- 整数类型：大小是类型名的一部分（int8、int16、...）---
	fmt.Println("Integer types:")
	fmt.Printf("  int8 : %d .. %d\n", math.MinInt8, math.MaxInt8)
	fmt.Printf("  int16: %d .. %d\n", math.MinInt16, math.MaxInt16)
	fmt.Printf("  int32: %d .. %d\n", math.MinInt32, math.MaxInt32)
	fmt.Printf("  int64: %d .. %d\n", math.MinInt64, math.MaxInt64)
	fmt.Printf("  uint8 (byte): 0 .. %d\n", math.MaxUint8)
	var i int
	fmt.Printf("  int  : %d bits on this machine\n", unsafe.Sizeof(i)*8)

	// --- 实数类型 ---
	fmt.Println("Real types:")
	fmt.Printf("  float32: max %e\n", math.MaxFloat32)
	fmt.Printf("  float64: max %e\n", math.MaxFloat64)

	// --- 字面量 ---
	decimal := 42
	hex := 0x2A
	binary := 0b101010
	big := 9_000_000_000 // Go 没有 L 后缀；int 是 64 位
	var f float32 = 2.5
	d := 2.5e3
	fmt.Println("Literals:", decimal, hex, binary, big, f, d)

	// --- 字符：Go 中的 rune 是一个 Unicode 码点（int32）---
	c := 'A'
	fmt.Printf("Character: %c, code: %d, type: %T\n", c, c, c)
	fmt.Printf("Next character: %c\n", c+1)
	zh := '中'
	fmt.Printf("Chinese character: %c, code: %d\n", zh, zh)

	// --- 布尔类型 ---
	isEven := decimal%2 == 0
	fmt.Println("Is 42 even?", isEven)

	// --- 声明变量：var（默认为“零值”）或：= ---
	var count int   // 0
	var name string // ""
	var ok bool     // false
	fmt.Printf("Zero values: %d %q %v\n", count, name, ok)

	// --- 常量 ---
	r := 2.0
	fmt.Println("Area of a circle (r=2):", Pi*r*r)
	fmt.Println("Number of days in 3 weeks:", 3*DaysInWeek)
}
