Go语言——math包
概述:
- 使⽤时需要import “math”,math包提供了基本的数学常数和数学函数。
math包中函数
- func NaN() float64
- func IsNaN(f float64) (is bool)
- func Inf(sign int) float64
- func IsInf(f float64, sign int) bool
- func Float32bits(f float32) uint32
- func Float32frombits(b uint32) float32
- func Float64bits(f float64) uint64
- func Float64frombits(b uint64) float64
- func Signbit(x float64) bool
- func Copysign(x, y float64) float64
- func Ceil(x float64) float64
- func Floor(x float64) float64
- func Trunc(x float64) float64
- func Modf(f float64) (int float64, frac float64)
- func Nextafter(x, y float64) (r float64)
- func Abs(x float64) float64
- func Max(x, y float64) float64
- func Min(x, y float64) float64
- func Dim(x, y float64) float64
- func Mod(x, y float64) float64
- func Remainder(x, y float64) float64
- func Sqrt(x float64) float64
- func Cbrt(x float64) float64
- func Hypot(p, q float64) float64
- func Sin(x float64) float64
- func Cos(x float64) float64
- func Tan(x float64) float64
- func Sincos(x float64) (sin, cos float64)
- func Asin(x float64) float64
- func Acos(x float64) float64
- func Atan(x float64) float64
- func Atan2(y, x float64) float64
- func Sinh(x float64) float64
- func Cosh(x float64) float64
- func Tanh(x float64) float64
- func Asinh(x float64) float64
- func Acosh(x float64) float64
- func Atanh(x float64) float64
- func Log(x float64) float64
- func Log1p(x float64) float64
- func Log2(x float64) float64
- func Log10(x float64) float64
- func Logb(x float64) float64
- func Ilogb(x float64) int
- func Frexp(f float64) (frac float64, exp int)
- func Ldexp(frac float64, exp int) float64
- func Exp(x float64) float64
- func Expm1(x float64) float64
- func Exp2(x float64) float64
- func Pow(x, y float64) float64
- func Pow10(e int) float64
- func Gamma(x float64) float64
- func Lgamma(x float64) (lgamma float64, sign int)
- func Erf(x float64) float64
- func Erfc(x float64) float64
- func J0(x float64) float64
- func J1(x float64) float64
- func Jn(n int, x float64) float64
- func Y0(x float64) float64
- func Y1(x float64) float64
- func Yn(n int, x float64) float64
math包中核⼼函数介绍
- func IsNaN(f float64) (is bool)
报告f是否表示⼀个NaN(Not A Number)值。 - func Ceil(x float64) float64
返回不⼩于x的最⼩整数(的浮点值) - func Floor(x float64) float64
返回不⼤于x的最⼩整数(的浮点值) - func Trunc(x float64) float64
返回x的整数部分(的浮点值)。 - func Abs(x float64) float64
返回x的绝对值 - func Max(x, y float64) float64
返回x和y中最⼤值 - func Min(x, y float64) float64
返回x和y中最⼩值 - func Dim(x, y float64) float64
函数返回x-y和0中的最⼤值 - func Mod(x, y float64) float64
取余运算,可以理解为 x-Trunc(x/y)*y,结果的正负号和x相同 - func Sqrt(x float64) float64
返回x的⼆次⽅根 - func Cbrt(x float64) float64
返回x的三次⽅根,特例如下: - func Hypot(p, q float64) float64
返回Sqrt(pp + qq) - func Pow(x, y float64) float64
返回x^y - func Sin(x float64) float64
求正弦。 - func Cos(x float64) float64
求余弦。 - func Tan(x float64) float64
求正切。 - func Log(x float64) float64
求⾃然对数 - func Log2(x float64) float64
求2为底的对数。 - func Log10(x float64) float64
求10为底的对数。