basictypes.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Basic Types
  2. package examples
  3. import (
  4. "fmt"
  5. "math"
  6. "math/cmplx"
  7. )
  8. var (
  9. ToBe bool = false
  10. Word string = "A Word"
  11. MaximumInt int = math.MaxInt32
  12. MinimumInt int = math.MinInt32
  13. MaximumInt8 int8 = math.MaxInt8
  14. MinimumInt8 int8 = math.MinInt8
  15. MaximumInt16 int16 = math.MaxInt16
  16. MinimumInt16 int16 = math.MinInt16
  17. MaximumInt64 int64 = math.MaxInt64
  18. MinimumInt64 int64 = math.MinInt64
  19. Uint8 uint8 = math.MaxUint8
  20. Uint16 uint16 = math.MaxUint16
  21. Uint32 uint32 = math.MaxUint32
  22. Uint64 uint64 = math.MaxUint64
  23. Byte byte = math.MaxUint8
  24. Rune rune = math.MaxInt32
  25. MaximumFloat32 float32 = math.MaxFloat32
  26. MinimumFloat32 float32 = math.SmallestNonzeroFloat32
  27. MaximumFloat64 float64 = math.MaxFloat64
  28. MinimumFloat64 float64 = math.SmallestNonzeroFloat64
  29. UintPtr uintptr = 0
  30. Z complex128 = cmplx.Sqrt(-5 + 12i)
  31. )
  32. func printTypeInfo(i interface{}) {
  33. fmt.Printf("Type: %T Value: %v\n", i, i)
  34. }
  35. func BasicTypes() {
  36. printTypeInfo(ToBe)
  37. printTypeInfo(Word)
  38. printTypeInfo(MaximumInt)
  39. printTypeInfo(MinimumInt)
  40. printTypeInfo(MaximumInt8)
  41. printTypeInfo(MinimumInt8)
  42. printTypeInfo(MaximumInt16)
  43. printTypeInfo(MinimumInt16)
  44. printTypeInfo(MaximumInt64)
  45. printTypeInfo(MinimumInt64)
  46. printTypeInfo(Uint8)
  47. printTypeInfo(Uint16)
  48. printTypeInfo(Uint32)
  49. printTypeInfo(Uint64)
  50. printTypeInfo(Byte)
  51. printTypeInfo(Rune)
  52. printTypeInfo(MaximumFloat32)
  53. printTypeInfo(MinimumFloat32)
  54. printTypeInfo(MaximumFloat64)
  55. printTypeInfo(MinimumFloat64)
  56. printTypeInfo(UintPtr)
  57. printTypeInfo(Z)
  58. }