3 Star 6 Fork 1

lihao1988/php2go

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
math.go 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
liguangmin 提交于 2023-02-09 16:09 +08:00 . php2go syn github
package math
import (
"math"
"strconv"
)
// Abs absolute value
// php abs
func Abs(x float64) float64 {
return math.Abs(x)
}
// Round number round
// php round
func Round(x float64) int64 {
return int64(math.Floor(x + 0.5))
}
// Floor returns the greatest integer value less than or equal to x
// php floor
func Floor(x float64) float64 {
return math.Floor(x)
}
// Ceil returns the least integer value greater than or equal to x
// php ceil
func Ceil(x float64) float64 {
return math.Ceil(x)
}
// Max returns the max num in nums
// php max
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
}
// Min returns the min num in nums
// php min
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
}
// DecBin Decimal to binary
// php decbin
func DecBin(number int64) string {
return strconv.FormatInt(number, 2)
}
// DecHex Decimal to hexadecimal
// php dechex
func DecHex(number int64) string {
return strconv.FormatInt(number, 16)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/lihao1988/php2go.git
git@gitee.com:lihao1988/php2go.git
lihao1988
php2go
php2go
v1.2.1

搜索帮助