File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ package math_
2+
3+ import (
4+ "fmt"
5+ "math"
6+ )
7+
8+ type mm struct {
9+ min , max interface {}
10+ }
11+
12+ // MinMaxは各数値型の最小値と最大値を表示するサンプルです
13+ func MinMax () error {
14+
15+ // 各数値型の最小値と最大値は math パッケージに定義されている
16+ // Floatのみ、MinXXではなくて SmallestNonzeroFloatXX となる
17+ m := map [string ]* mm {
18+ "Int8" : {min : math .MinInt8 , max : math .MaxInt8 },
19+ "Int16" : {min : math .MinInt16 , max : math .MaxInt16 },
20+ "Int32" : {min : math .MinInt32 , max : math .MaxInt32 },
21+ "Int64" : {min : math .MinInt64 , max : math .MaxInt64 },
22+ }
23+
24+ for k , v := range m {
25+ fmt .Printf ("%v Min[%v] Max[%v]\n " , k , v .min , v .max )
26+ }
27+
28+ return nil
29+ }
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import (
1717 "github.com/devlights/try-golang/basic/io_"
1818 "github.com/devlights/try-golang/basic/iota_"
1919 "github.com/devlights/try-golang/basic/map_"
20+ "github.com/devlights/try-golang/basic/math_"
2021 "github.com/devlights/try-golang/basic/os_"
2122 "github.com/devlights/try-golang/basic/runtime_"
2223 "github.com/devlights/try-golang/basic/scope"
@@ -87,4 +88,5 @@ func (m SampleMapping) MakeMapping() {
8788 m ["function_multi_return_value" ] = functions .FunctionMultiReturnValue
8889 m ["function_named_return_value" ] = functions .FunctionNamedReturnValue
8990 m ["type01" ] = type_ .Type01
91+ m ["minmax" ] = math_ .MinMax
9092}
You can’t perform that action at this time.
0 commit comments