golang中的math包常用的api

1.func Abs(x float64) float64

//求绝对值
fmt.Println(math.Abs(-1.11))//1.11

2.func Pow(x, y float64) float64

//求x的n次方
fmt.Println(math.Pow(2, 16))//65536

3.func Sqrt(x float64) float64

//取x的开平方
fmt.Println(math.Sqrt(64))//8

4.func Cbrt(x float64) float64

//取x的开立方
fmt.Println(math.Cbrt(27))//3

5.func Ceil(x float64) float64

//向上取整
fmt.Println(math.Ceil(3.14))//4

6.func Floor(x float64) float64

//向下取整
fmt.Println(math.Floor(8.75))//8

7.func Modf(f float64) (int float64, frac float64)

//分别取整数和小数部分
Integer, Decimal := math.Modf(3.14159265358979)
fmt.Println(Integer, Decimal)//3 0.14159265358979

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值