interface_task.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package main
  2. import (
  3. "fmt"
  4. )
  5. func main() {
  6. foo1()
  7. /*
  8. value1, value2, operation := readTask()
  9. switch v1 := value1.(type) {
  10. case float64:
  11. break
  12. default:
  13. fmt.Printf("value=%v: %T\n", v1, v1)
  14. return
  15. }
  16. switch v2 := value2.(type) {
  17. case float64:
  18. break
  19. default:
  20. fmt.Printf("value=%v: %T\n", v2, v2)
  21. return
  22. }
  23. switch op := operation.(type) {
  24. case string:
  25. if op == "+" {
  26. fmt.Printf("%.4f\n", value1.(float64)+value2.(float64))
  27. } else if op == "-" {
  28. fmt.Printf("%.4f\n", value1.(float64)-value2.(float64))
  29. } else if op == "*" {
  30. fmt.Printf("%.4f\n", value1.(float64)*value2.(float64))
  31. } else if op == "/" {
  32. fmt.Printf("%.4f\n", value1.(float64)/value2.(float64))
  33. }
  34. default:
  35. fmt.Printf("operation=%v: %T\n", op, op)
  36. return
  37. }
  38. // fmt.Println("value 1 - OK")
  39. // fmt.Println(value1, value2, operation)
  40. */
  41. }
  42. func foo1() {
  43. // vi1, vi2, operation := readTask()
  44. // vi := [2]interface{}{vi1, vi2}
  45. var v1, v2 float64
  46. vf := [2]*float64{&v1, &v2}
  47. fmt.Println(vf)
  48. fmt.Printf("%v %T", vf, vf)
  49. }
  50. func readTask() (v1, v2, op interface{}) {
  51. v1 = 12.36
  52. v2 = 36.24
  53. op = "+"
  54. return
  55. }