Skip to content

Commit

Permalink
feat: maths 包支持奇偶数判断
Browse files Browse the repository at this point in the history
  • Loading branch information
kercylan98 committed Jul 29, 2023
1 parent 997bbbe commit ac43963
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions utils/maths/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,13 @@ func JoinNumbers[V generic.Number](num1 V, n ...V) V {
}
return v
}

// IsOdd 返回 n 是否为奇数
func IsOdd[V generic.Integer](n V) bool {
return 0 != (int64(n) & 1)
}

// IsEven 返回 n 是否为偶数
func IsEven[V generic.Integer](n V) bool {
return 0 == (int64(n) & 1)
}

0 comments on commit ac43963

Please sign in to comment.