Documentation ¶
Index ¶
- Constants
- func Clamp[V generic.Number](value, min, max V) V
- func Compare[V generic.Ordered](a V, expression CompareExpression, b V) bool
- func GetDefaultTolerance() float64
- func IsContinuity[V generic.Integer](values []V) bool
- func IsContinuityWithSort[V generic.Integer](values []V) bool
- func Max[V generic.Number](a, b V) V
- func MaxMin[V generic.Number](a, b V) (max, min V)
- func Merge[V generic.SignedNumber](refer, a, b V) V
- func Min[V generic.Number](a, b V) V
- func MinMax[V generic.Number](a, b V) (min, max V)
- func Pow(a, n int) int
- func PowInt64(a, n int64) int64
- func ToContinuous[V generic.Integer](nums []V) map[V]V
- func Tolerance[V generic.Number](value1, value2, tolerance V) bool
- func UnMerge[V generic.SignedNumber](refer, num V) (a, b V)
- type CompareExpression
Examples ¶
Constants ¶
View Source
const (
DefaultTolerance = 0.0001 // 默认误差范围
)
Variables ¶
This section is empty.
Functions ¶
func Compare ¶
func Compare[V generic.Ordered](a V, expression CompareExpression, b V) bool
Compare 根据特定表达式比较两个值
func IsContinuity ¶ added in v0.0.3
IsContinuity 检查一组值是否连续
Example ¶
package main import ( "fmt" "github.com/kercylan98/minotaur/utils/maths" ) func main() { fmt.Println(maths.IsContinuity([]int{1, 2, 3, 4, 5, 6, 7})) fmt.Println(maths.IsContinuity([]int{1, 2, 3, 5, 5, 6, 7})) }
Output: true false
func IsContinuityWithSort ¶ added in v0.0.3
IsContinuityWithSort 检查一组值排序后是否连续
func ToContinuous ¶ added in v0.0.3
ToContinuous 将一组非连续的数字转换为从1开始的连续数字
- 返回值是一个 map,key 是从 1 开始的连续数字,value 是原始数字
Example ¶
package main import ( "fmt" "github.com/kercylan98/minotaur/utils/maths" ) func main() { var nums = []int{1, 2, 3, 5, 6, 7, 9, 10, 11} var continuous = maths.ToContinuous(nums) fmt.Println(nums) fmt.Println(continuous) }
Output: [1 2 3 5 6 7 9 10 11] map[1:1 2:2 3:3 4:5 5:6 6:7 7:9 8:10 9:11]
Types ¶
type CompareExpression ¶
type CompareExpression int
CompareExpression 比较表达式
const ( CompareGreaterThan CompareExpression = 1 // 大于 CompareGreaterThanOrEqual CompareExpression = 2 // 大于等于 CompareLessThan CompareExpression = 3 // 小于 CompareLessThanOrEqual CompareExpression = 4 // 小于等于 CompareEqual CompareExpression = 5 // 等于 )
Click to show internal directories.
Click to hide internal directories.