Package math

Overview ▾

程序包数学提供基本常量和数学函数.

该软件包不能保证跨体系结构的位相同结果.

Index ▾

Constants
func Abs(x float64) float64
func Acos(x float64) float64
func Acosh(x float64) float64
func Asin(x float64) float64
func Asinh(x float64) float64
func Atan(x float64) float64
func Atan2(y, x float64) float64
func Atanh(x float64) float64
func Cbrt(x float64) float64
func Ceil(x float64) float64
func Copysign(x, y float64) float64
func Cos(x float64) float64
func Cosh(x float64) float64
func Dim(x, y float64) float64
func Erf(x float64) float64
func Erfc(x float64) float64
func Erfcinv(x float64) float64
func Erfinv(x float64) float64
func Exp(x float64) float64
func Exp2(x float64) float64
func Expm1(x float64) float64
func Float32bits(f float32) uint32
func Float32frombits(b uint32) float32
func Float64bits(f float64) uint64
func Float64frombits(b uint64) float64
func Floor(x float64) float64
func Frexp(f float64) (frac float64, exp int)
func Gamma(x float64) float64
func Hypot(p, q float64) float64
func Ilogb(x float64) int
func Inf(sign int) float64
func IsInf(f float64, sign int) bool
func IsNaN(f float64) (is bool)
func J0(x float64) float64
func J1(x float64) float64
func Jn(n int, x float64) float64
func Ldexp(frac float64, exp int) float64
func Lgamma(x float64) (lgamma float64, sign int)
func Log(x float64) float64
func Log10(x float64) float64
func Log1p(x float64) float64
func Log2(x float64) float64
func Logb(x float64) float64
func Max(x, y float64) float64
func Min(x, y float64) float64
func Mod(x, y float64) float64
func Modf(f float64) (int float64, frac float64)
func NaN() float64
func Nextafter(x, y float64) (r float64)
func Nextafter32(x, y float32) (r float32)
func Pow(x, y float64) float64
func Pow10(n int) float64
func Remainder(x, y float64) float64
func Round(x float64) float64
func RoundToEven(x float64) float64
func Signbit(x float64) bool
func Sin(x float64) float64
func Sincos(x float64) (sin, cos float64)
func Sinh(x float64) float64
func Sqrt(x float64) float64
func Tan(x float64) float64
func Tanh(x float64) float64
func Trunc(x float64) float64
func Y0(x float64) float64
func Y1(x float64) float64
func Yn(n int, x float64) float64

Package files

abs.go acosh.go asin.go asinh.go atan.go atan2.go atanh.go bits.go cbrt.go const.go copysign.go dim.go erf.go erfinv.go exp.go exp_asm.go expm1.go floor.go frexp.go gamma.go hypot.go j0.go j1.go jn.go ldexp.go lgamma.go log.go log10.go log1p.go logb.go mod.go modf.go nextafter.go pow.go pow10.go remainder.go signbit.go sin.go sincos.go sinh.go sqrt.go tan.go tanh.go trig_reduce.go unsafe.go

Constants

数学常数.

const (
    E   = 2.71828182845904523536028747135266249775724709369995957496696763 // https://oeis.org/A001113
    Pi  = 3.14159265358979323846264338327950288419716939937510582097494459 // https://oeis.org/A000796
    Phi = 1.61803398874989484820458683436563811772030917980576286213544862 // https://oeis.org/A001622

    Sqrt2   = 1.41421356237309504880168872420969807856967187537694807317667974 // https://oeis.org/A002193
    SqrtE   = 1.64872127070012814684865078781416357165377610071014801157507931 // https://oeis.org/A019774
    SqrtPi  = 1.77245385090551602729816748334114518279754945612238712821380779 // https://oeis.org/A002161
    SqrtPhi = 1.27201964951406896425242246173749149171560804184009624861664038 // https://oeis.org/A139339

    Ln2    = 0.693147180559945309417232121458176568075500134360255254120680009 // https://oeis.org/A002162
    Log2E  = 1 / Ln2
    Ln10   = 2.30258509299404568401799145468436420760110148862877297603332790 // https://oeis.org/A002392
    Log10E = 1 / Ln10
)

浮点极限值. Max是该类型可表示的最大有限值. SmallestNonzero是该类型可表示的最小正非零值.

const (
    MaxFloat32             = 3.40282346638528859811704183484516925440e+38  // 2**127 * (2**24 - 1) / 2**23
    SmallestNonzeroFloat32 = 1.401298464324817070923729583289916131280e-45 // 1 / 2**(127 - 1 + 23)

    MaxFloat64             = 1.797693134862315708145274237317043567981e+308 // 2**1023 * (2**53 - 1) / 2**52
    SmallestNonzeroFloat64 = 4.940656458412465441765687928682213723651e-324 // 1 / 2**(1023 - 1 + 52)
)

整数极限值.

const (
    MaxInt8   = 1<<7 - 1
    MinInt8   = -1 << 7
    MaxInt16  = 1<<15 - 1
    MinInt16  = -1 << 15
    MaxInt32  = 1<<31 - 1
    MinInt32  = -1 << 31
    MaxInt64  = 1<<63 - 1
    MinInt64  = -1 << 63
    MaxUint8  = 1<<8 - 1
    MaxUint16 = 1<<16 - 1
    MaxUint32 = 1<<32 - 1
    MaxUint64 = 1<<64 - 1
)

func Abs

func Abs(x float64) float64

Abs返回x的绝对值.

特殊情况是:

Abs(±Inf) = +Inf
Abs(NaN) = NaN

Example

2.0
2.0

func Acos

func Acos(x float64) float64

Acos返回弧度的x的反余弦值.

特殊情况是:

Acos(x) = NaN if x < -1 or x > 1

Example

0.00

func Acosh

func Acosh(x float64) float64

Acosh返回x的反双曲余弦值.

特殊情况是:

Acosh(+Inf) = +Inf
Acosh(x) = NaN if x < 1
Acosh(NaN) = NaN

Example

0.00

func Asin

func Asin(x float64) float64

Asin返回弧度的x的反正弦值.

特殊情况是:

Asin(±0) = ±0
Asin(x) = NaN if x < -1 or x > 1

Example

0.00

func Asinh

func Asinh(x float64) float64

Asinh返回x的反双曲正弦值.

特殊情况是:

Asinh(±0) = ±0
Asinh(±Inf) = ±Inf
Asinh(NaN) = NaN

Example

0.00

func Atan

func Atan(x float64) float64

Atan返回弧度的x的反正切值.

特殊情况是:

Atan(±0) = ±0
Atan(±Inf) = ±Pi/2

Example

0.00

func Atan2

func Atan2(y, x float64) float64

Atan2返回y / x的反正切,使用两者的符号确定返回值的象限.

特殊情况如下(按顺序):

Atan2(y, NaN) = NaN
Atan2(NaN, x) = NaN
Atan2(+0, x>=0) = +0
Atan2(-0, x>=0) = -0
Atan2(+0, x<=-0) = +Pi
Atan2(-0, x<=-0) = -Pi
Atan2(y>0, 0) = +Pi/2
Atan2(y<0, 0) = -Pi/2
Atan2(+Inf, +Inf) = +Pi/4
Atan2(-Inf, +Inf) = -Pi/4
Atan2(+Inf, -Inf) = 3Pi/4
Atan2(-Inf, -Inf) = -3Pi/4
Atan2(y, +Inf) = 0
Atan2(y>0, -Inf) = +Pi
Atan2(y<0, -Inf) = -Pi
Atan2(+Inf, x) = +Pi/2
Atan2(-Inf, x) = -Pi/2

Example

0.00

func Atanh

func Atanh(x float64) float64

Atanh返回x的反双曲正切值.

特殊情况是:

Atanh(1) = +Inf
Atanh(±0) = ±0
Atanh(-1) = -Inf
Atanh(x) = NaN if x < -1 or x > 1
Atanh(NaN) = NaN

Example

0.00

func Cbrt

func Cbrt(x float64) float64

Cbrt返回x的立方根.

特殊情况是:

Cbrt(±0) = ±0
Cbrt(±Inf) = ±Inf
Cbrt(NaN) = NaN

func Ceil

func Ceil(x float64) float64

Ceil返回大于或等于x的最小整数值.

特殊情况是:

Ceil(±0) = ±0
Ceil(±Inf) = ±Inf
Ceil(NaN) = NaN

Example

2.0

func Copysign

func Copysign(x, y float64) float64

Copysign返回一个值为x且值为y的值.

func Cos

func Cos(x float64) float64

Cos返回弧度参数x的余弦值.

特殊情况是:

Cos(±Inf) = NaN
Cos(NaN) = NaN

Example

0.00

func Cosh

func Cosh(x float64) float64

Cosh返回x的双曲余弦值.

特殊情况是:

Cosh(±0) = 1
Cosh(±Inf) = +Inf
Cosh(NaN) = NaN

Example

1.00

func Dim

func Dim(x, y float64) float64

Dim返回xy或0的最大值.

特殊情况是:

Dim(+Inf, +Inf) = NaN
Dim(-Inf, -Inf) = NaN
Dim(x, NaN) = Dim(NaN, x) = NaN

func Erf

func Erf(x float64) float64

Erf返回x的误差函数.

特殊情况是:

Erf(+Inf) = 1
Erf(-Inf) = -1
Erf(NaN) = NaN

func Erfc

func Erfc(x float64) float64

Erfc返回x的互补误差函数.

特殊情况是:

Erfc(+Inf) = 0
Erfc(-Inf) = 2
Erfc(NaN) = NaN

func Erfcinv 1.10

func Erfcinv(x float64) float64

Erfcinv返回Erfc(x)的逆.

特殊情况是:

Erfcinv(0) = +Inf
Erfcinv(2) = -Inf
Erfcinv(x) = NaN if x < 0 or x > 2
Erfcinv(NaN) = NaN

func Erfinv 1.10

func Erfinv(x float64) float64

Erfinv返回x的反误差函数.

特殊情况是:

Erfinv(1) = +Inf
Erfinv(-1) = -Inf
Erfinv(x) = NaN if x < -1 or x > 1
Erfinv(NaN) = NaN

func Exp

func Exp(x float64) float64

Exp返回e ** x,x的基数e指数.

特殊情况是:

Exp(+Inf) = +Inf
Exp(NaN) = NaN

很大的值溢出到0或+ Inf. 很小的值下溢至1.

func Exp2

func Exp2(x float64) float64

Exp2返回2 ** x,x的以2为底的指数.

特殊情况与Exp相同.

func Expm1

func Expm1(x float64) float64

Expm1返回e ** x-1,x的基数e减去1.当x接近零时,它比Exp(x)-1更精确.

特殊情况是:

Expm1(+Inf) = +Inf
Expm1(-Inf) = -1
Expm1(NaN) = NaN

很大的值溢出到-1或+ Inf.

func Float32bits

func Float32bits(f float32) uint32

Float32bits返回f的IEEE 754二进制表示形式,其中f的符号位和结果位于相同的位位置. Float32bits(Float32frombits(x))== x.

func Float32frombits

func Float32frombits(b uint32) float32

Float32frombits返回与IEEE 754二进制表示形式b相对应的浮点数,其符号位b和结果位于相同的位位置. Float32frombits(Float32bits(x))== x.

func Float64bits

func Float64bits(f float64) uint64

Float64bits返回f的IEEE 754二进制表示形式,其中f的符号位和结果位于相同的位位置,并且Float64bits(Float64frombits(x))== x.

func Float64frombits

func Float64frombits(b uint64) float64

Float64frombits返回对应于IEEE 754二进制表示形式b的浮点数,其符号位b和结果位于相同的位位置. Float64frombits(Float64bits(x))== x.

func Floor

func Floor(x float64) float64

Floor返回小于或等于x的最大整数值.

特殊情况是:

Floor(±0) = ±0
Floor(±Inf) = ±Inf
Floor(NaN) = NaN

Example

1.0

func Frexp

func Frexp(f float64) (frac float64, exp int)

Frexp将f分解为归一化分数和2的整数次方. 它返回frac和exp,满足f == frac×2 ** exp,而frac的绝对值在[1/2,1)区间内.

特殊情况是:

Frexp(±0) = ±0, 0
Frexp(±Inf) = ±Inf, 0
Frexp(NaN) = NaN, 0

func Gamma

func Gamma(x float64) float64

Gamma返回x的Gamma函数.

特殊情况是:

Gamma(+Inf) = +Inf
Gamma(+0) = +Inf
Gamma(-0) = -Inf
Gamma(x) = NaN for integer x < 0
Gamma(-Inf) = NaN
Gamma(NaN) = NaN

func Hypot

func Hypot(p, q float64) float64

Hypot返回Sqrt(p * p + q * q),请注意避免不必要的上溢和下溢.

特殊情况是:

Hypot(±Inf, q) = +Inf
Hypot(p, ±Inf) = +Inf
Hypot(NaN, q) = NaN
Hypot(p, NaN) = NaN

func Ilogb

func Ilogb(x float64) int

Ilogb以整数形式返回x的二进制指数.

特殊情况是:

Ilogb(±Inf) = MaxInt32
Ilogb(0) = MinInt32
Ilogb(NaN) = MaxInt32

func Inf

func Inf(sign int) float64

如果符号> = 0,则Inf返回正无穷大;如果符号<0,则Inf返回负无穷大.

func IsInf

func IsInf(f float64, sign int) bool

IsInf根据符号报告f是否为无穷大. 如果sign> 0,则IsInf报告f是否为正无穷大. 如果符号<0,则IsInf报告f是否为负无穷大. 如果符号== 0,则IsInf报告f是否为无穷大.

func IsNaN

func IsNaN(f float64) (is bool)

IsNaN报告f是否为IEEE 754"非数字"值.

func J0

func J0(x float64) float64

J0返回第一种零阶贝塞尔函数.

特殊情况是:

J0(±Inf) = 0
J0(0) = 1
J0(NaN) = NaN

func J1

func J1(x float64) float64

J1返回第一类的一阶贝塞尔函数.

特殊情况是:

J1(±Inf) = 0
J1(NaN) = NaN

func Jn

func Jn(n int, x float64) float64

Jn返回第一种n阶贝塞尔函数.

特殊情况是:

Jn(n, ±Inf) = 0
Jn(n, NaN) = NaN

func Ldexp

func Ldexp(frac float64, exp int) float64

Ldexp是Frexp的逆. 它返回frac×2 ** exp.

特殊情况是:

Ldexp(±0, exp) = ±0
Ldexp(±Inf, exp) = ±Inf
Ldexp(NaN, exp) = NaN

func Lgamma

func Lgamma(x float64) (lgamma float64, sign int)

Lgamma返回Gamma(x)的自然对数和符号(-1或+1).

特殊情况是:

Lgamma(+Inf) = +Inf
Lgamma(0) = +Inf
Lgamma(-integer) = +Inf
Lgamma(-Inf) = -Inf
Lgamma(NaN) = NaN

func Log

func Log(x float64) float64

对数返回x的自然对数.

特殊情况是:

Log(+Inf) = +Inf
Log(0) = -Inf
Log(x < 0) = NaN
Log(NaN) = NaN

Example

0.0
1.0

func Log10

func Log10(x float64) float64

Log10返回x的十进制对数. 特殊情况与Log相同.

Example

2.0

func Log1p

func Log1p(x float64) float64

Log1p returns the natural logarithm of 1 plus its argument x. It is more accurate than Log(1 + x) when x is near zero.

特殊情况是:

Log1p(+Inf) = +Inf
Log1p(±0) = ±0
Log1p(-1) = -Inf
Log1p(x < -1) = NaN
Log1p(NaN) = NaN

func Log2

func Log2(x float64) float64

Log2返回x的二进制对数. 特殊情况与Log相同.

Example

8.0

func Logb

func Logb(x float64) float64

Logb返回x的二进制指数.

特殊情况是:

Logb(±Inf) = +Inf
Logb(0) = -Inf
Logb(NaN) = NaN

func Max

func Max(x, y float64) float64

最大值返回x或y中的较大者.

特殊情况是:

Max(x, +Inf) = Max(+Inf, x) = +Inf
Max(x, NaN) = Max(NaN, x) = NaN
Max(+0, ±0) = Max(±0, +0) = +0
Max(-0, -0) = -0

func Min

func Min(x, y float64) float64

Min返回x或y中的较小者.

特殊情况是:

Min(x, -Inf) = Min(-Inf, x) = -Inf
Min(x, NaN) = Min(NaN, x) = NaN
Min(-0, ±0) = Min(±0, -0) = -0

func Mod

func Mod(x, y float64) float64

Mod返回x / y的浮点余数. 结果的幅度小于y,其符号与x一致.

特殊情况是:

Mod(±Inf, y) = NaN
Mod(NaN, y) = NaN
Mod(x, 0) = NaN
Mod(x, ±Inf) = x
Mod(x, NaN) = NaN

Example

3.0

func Modf

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

Modf返回整数和小数浮点数,其总和为f. 这两个值与f具有相同的符号.

特殊情况是:

Modf(±Inf) = ±Inf, NaN
Modf(NaN) = NaN, NaN

func NaN

func NaN() float64

NaN返回IEEE 754"非数字"值.

func Nextafter

func Nextafter(x, y float64) (r float64)

Nextafter返回x之​​后到y的下一个可表示的float64值.

特殊情况是:

Nextafter(x, x)   = x
Nextafter(NaN, y) = NaN
Nextafter(x, NaN) = NaN

func Nextafter32 1.4

func Nextafter32(x, y float32) (r float32)

Nextafter32返回x之后朝向y的下一个可表示的float32值.

特殊情况是:

Nextafter32(x, x)   = x
Nextafter32(NaN, y) = NaN
Nextafter32(x, NaN) = NaN

func Pow

func Pow(x, y float64) float64

Pow返回x ** y,即y的基数x指数.

特殊情况如下(按顺序):

Pow(x, ±0) = 1 for any x
Pow(1, y) = 1 for any y
Pow(x, 1) = x for any x
Pow(NaN, y) = NaN
Pow(x, NaN) = NaN
Pow(±0, y) = ±Inf for y an odd integer < 0
Pow(±0, -Inf) = +Inf
Pow(±0, +Inf) = +0
Pow(±0, y) = +Inf for finite y < 0 and not an odd integer
Pow(±0, y) = ±0 for y an odd integer > 0
Pow(±0, y) = +0 for finite y > 0 and not an odd integer
Pow(-1, ±Inf) = 1
Pow(x, +Inf) = +Inf for |x| > 1
Pow(x, -Inf) = +0 for |x| > 1
Pow(x, +Inf) = +0 for |x| < 1
Pow(x, -Inf) = +Inf for |x| < 1
Pow(+Inf, y) = +Inf for y > 0
Pow(+Inf, y) = +0 for y < 0
Pow(-Inf, y) = Pow(-0, -y)
Pow(x, y) = NaN for finite x < 0 and finite non-integer y

Example

8.0

func Pow10

func Pow10(n int) float64

Pow10返回10 ** n,即n的以10为底的指数.

特殊情况是:

Pow10(n) =    0 for n < -323
Pow10(n) = +Inf for n > 308

Example

100.0

func Remainder

func Remainder(x, y float64) float64

余数返回x / y的IEEE 754浮点数余数.

特殊情况是:

Remainder(±Inf, y) = NaN
Remainder(NaN, y) = NaN
Remainder(x, 0) = NaN
Remainder(x, ±Inf) = x
Remainder(x, NaN) = NaN

func Round 1.10

func Round(x float64) float64

舍入返回最接近的整数,从零舍入一半.

特殊情况是:

Round(±0) = ±0
Round(±Inf) = ±Inf
Round(NaN) = NaN

Example

11.0
-11.0

func RoundToEven 1.10

func RoundToEven(x float64) float64

RoundToEven返回最接近的整数,四舍五入为偶数.

特殊情况是:

RoundToEven(±0) = ±0
RoundToEven(±Inf) = ±Inf
RoundToEven(NaN) = NaN

Example

12.0
12.0

func Signbit

func Signbit(x float64) bool

Signbit报告x是负数还是负零.

func Sin

func Sin(x float64) float64

Sin返回弧度参数x的正弦值.

特殊情况是:

Sin(±0) = ±0
Sin(±Inf) = NaN
Sin(NaN) = NaN

Example

0.00

func Sincos

func Sincos(x float64) (sin, cos float64)

Sincos返回Sin(x),Cos(x).

特殊情况是:

Sincos(±0) = ±0, 1
Sincos(±Inf) = NaN, NaN
Sincos(NaN) = NaN, NaN

Example

0.00, 1.00

func Sinh

func Sinh(x float64) float64

Sinh返回x的双曲正弦值.

特殊情况是:

Sinh(±0) = ±0
Sinh(±Inf) = ±Inf
Sinh(NaN) = NaN

Example

0.00

func Sqrt

func Sqrt(x float64) float64

Sqrt返回x的平方根.

特殊情况是:

Sqrt(+Inf) = +Inf
Sqrt(±0) = ±0
Sqrt(x < 0) = NaN
Sqrt(NaN) = NaN

Example

5.0

func Tan

func Tan(x float64) float64

Tan返回弧度参数x的切线.

特殊情况是:

Tan(±0) = ±0
Tan(±Inf) = NaN
Tan(NaN) = NaN

Example

0.00

func Tanh

func Tanh(x float64) float64

Tanh返回x的双曲正切值.

特殊情况是:

Tanh(±0) = ±0
Tanh(±Inf) = ±1
Tanh(NaN) = NaN

Example

0.00

func Trunc

func Trunc(x float64) float64

Trunc返回x的整数值.

特殊情况是:

Trunc(±0) = ±0
Trunc(±Inf) = ±Inf
Trunc(NaN) = NaN

func Y0

func Y0(x float64) float64

Y0返回第二种零阶贝塞尔函数.

特殊情况是:

Y0(+Inf) = 0
Y0(0) = -Inf
Y0(x < 0) = NaN
Y0(NaN) = NaN

func Y1

func Y1(x float64) float64

Y1返回第二种一阶贝塞尔函数.

特殊情况是:

Y1(+Inf) = 0
Y1(0) = -Inf
Y1(x < 0) = NaN
Y1(NaN) = NaN

func Yn

func Yn(n int, x float64) float64

Yn返回第二种n阶贝塞尔函数.

特殊情况是:

Yn(n, +Inf) = 0
Yn(n ≥ 0, 0) = -Inf
Yn(n < 0, 0) = +Inf if n is odd, -Inf if n is even
Yn(n, x < 0) = NaN
Yn(n, NaN) = NaN

Subdirectories

Name Synopsis
..
big 包big实现任意精度算术(大数).
bits 包位为预声明的无符号整数类型实现位计数和操作功能.
cmplx 包cmplx为复数提供基本常数和数学函数.
rand 包rand实现伪随机数生成器.

by  ICOPY.SITE