123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package math
- import (
- "math"
- "strconv"
- )
- func Abs(x float64) float64 {
- return math.Abs(x)
- }
- func Round(x float64) int64 {
- return int64(math.Floor(x + 0.5))
- }
- func Floor(x float64) float64 {
- return math.Floor(x)
- }
- func Ceil(x float64) float64 {
- return math.Ceil(x)
- }
- func Max(nums ...float64) float64 {
- if len(nums) < 2 {
- panic("nums: the nums length is less than 2")
- }
- maxNum := nums[0]
- for i := 1; i < len(nums); i++ {
- maxNum = math.Max(maxNum, nums[i])
- }
- return maxNum
- }
- func Min(nums ...float64) float64 {
- if len(nums) < 2 {
- panic("nums: the nums length is less than 2")
- }
- minNum := nums[0]
- for i := 1; i < len(nums); i++ {
- minNum = math.Min(minNum, nums[i])
- }
- return minNum
- }
- func DecBin(number int64) string {
- return strconv.FormatInt(number, 2)
- }
- func DecHex(number int64) string {
- return strconv.FormatInt(number, 16)
- }
|