Skip to content

Commit 31b319c

Browse files
authored
Merge pull request #105 from devlights/issue-#103
Add minmax example ( close #103 )
2 parents 98996a6 + 0c02bb2 commit 31b319c

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

basic/math_/minmax.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
}

lib/mapping.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)