Go 语言为基本常量和数学函数提供内置支持,以在 math 包的帮助下对数字执行运算。
Function | Description |
---|---|
Abs | This function is used to return the absolute value of the specified number. |
Acos | This function returns the arccosine, in radians of the specified number. |
Acosh | This function returns the inverse hyperbolic cosine of the specified number. |
Asin | This function returns the arcsine, in radians of the specified number. |
Asinh | This function returns the inverse hyperbolic sine of the specified number. |
Atan | This function returns the arctangent, in radians of the specified number. |
Atan2 | This function returns the arc tangent of a/b, using the signs of the two to determine the quadrant of the return value. |
Atanh | This function returns the inverse hyperbolic tangent of the specified number. |
Cbrt | This function returns the cube root of the specified number. |
Ceil | This function returns the least integer value greater than or equal to the specified number. |
Copysign | This function returns a value with the magnitude of a and the sign of b. |
Cos | This function returns the cosine of the radian argument of the specified number. |
Cosh | This function returns the hyperbolic cosine of the specified number. |
Dim | This function returns the maximum of a – b or 0. |
Erf | This function returns the error function of the specified number. |
Erfc | This function returns the complementary error function of the specified number. |
Erfcinv | This function returns the inverse of Erfc(y). |
Erfinv | This function returns the inverse error function of the specified number. |
Exp | This function returns e**y, the base-e exponential of the specified number. |
Exp2 | This function returns 2**y, the base-2 exponential of the specified number. |
Expm1 | This function returns e**y – 1, the base-e exponential of y minus 1. |
FMA | This function returns a * b + c, computed with only one rounding. |
Float32bits | This function returns the IEEE 754 binary representation of x, with the sign bit of x and the result in the same bit position. |
Float32frombits | This function returns the floating-point number corresponding to the IEEE 754 binary representation x, with the sign bit of x and the result in the same bit position. |
Float64bits | This function returns the IEEE 754 binary representation of x, with the sign bit of x and the result in the same bit position, and Float64bits(Float64frombits(y)) == y. |
Float64frombits | This function returns the floating-point number corresponding to the IEEE 754 binary representation x, with the sign bit of x and the result in the same bit position. |
Floor | This function returns the greatest integer value less than or equal to the specified number. |
Frexp | This function is used to breaks t into a normalized fraction and an integral power of two and returns frac and exp satisfying t == frac × 2**exp, with the absolute value of frac in the interval [½, 1). |
Gamma | This function returns the Gamma function of the specified number. |
Hypot | This function returns Sqrt(a*a + b*b), taking care to avoid unnecessary overflow and underflow. |
Ilogb | This function returns the binary exponent of the specified number as an integer. |
Inf | This function returns positive infinity if sign >= 0, negative infinity if sign < 0. |
IsInf | This function reports whether t is an infinity, according to sign. |
IsNaN | This function reports whether t is an IEEE 754 “not-a-number” value. |
J0 | This function returns the order-zero Bessel function of the first kind. |
J1 | This function returns the order-one Bessel function of the first kind. |
Jn | This function returns the order-n Bessel function of the first kind. |
Ldexp | This function is the inverse of Frexp. |
Lgamma | This function returns the natural logarithm and sign (-1 or +1) of Gamma(y). |
Log | This function returns the natural logarithm of the specified number. |
Log10 | This function returns the decimal logarithm of the specified number. |
Log1p | This function returns the natural logarithm of 1 plus its argument of the specified number. |
Log2 | This function is used to return the binary logarithm of the specified number. |
Logb | This function returns the binary exponent of the specified number. |
Max | This function returns the larger of a or b. |
Min | This function returns the smaller of a or b. |
Mod | This function returns the floating-point remainder of a/b |
Modf | This function returns integer and fractional floating-point numbers that sum to f. |
NaN | This function returns an IEEE 754 “not-a-number” value. |
Nextafter | This function is used to return the next representable float64 value after a towards b. |
Nextafter32 | This function returns the next representable float32 value after a towards b. |
Pow | This function returns a**b, the base-a exponential of b. |
Pow10 | This function returns 10**m, the base-10 exponential of m. |
Remainder | This function returns the IEEE 754 floating-point remainder of a/b. |
Round | This function is used to return the nearest integer, rounding half away from zero. |
RoundToEven | This function returns the nearest integer, rounding ties to even. |
Signbit | This function reports whether x is negative or negative zero. |
Sin | This function returns the sine of the radian argument y. |
Sincos | This function returns Sin(x), Cos(x). |
Sinh | This function returns the hyperbolic sine of the specified number. |
Sqrt | This function returns the square root of the specified number. |
Tan | This function returns the tangent of the radian argument y. |
Tanh | This function returns the hyperbolic tangent of the specified number. |
Trunc | This function returns the integer value of the specified number. |
Y0 | This function returns the order-zero Bessel function of the second kind. |
Y1 | This function returns the order-one Bessel function of the second kind. |
Yn | This function returns the order-n Bessel function of the second kind. |
示例 1:
// Golang program to illustrate how to
// find the IEEE 754 binary representation
package main
import (
"fmt"
"math"
)
// Main function
func main() {
// Finding IEEE 754 binary
// representation of the
// given numbers
// Using Float64bits() function
res_1 := math.Float64bits(2)
res_2 := math.Float64bits(1)
res_3 := math.Float64bits(0)
res_4 := math.Float64bits(2.3)
// Displaying the result
fmt.Println("Result 1: ", res_1)
fmt.Println("Result 2: ", res_2)
fmt.Println("Result 3: ", res_3)
fmt.Println("Result 4: ", res_4)
}
输出:
Result 1: 4611686018427387904
Result 2: 4607182418800017408
Result 3: 0
Result 4: 4612361558371493478
示例 2:
// Golang program to illustrate
// the use of math.Yn() function
package main
import (
"fmt"
"math"
)
// Main function
func main() {
// Finding the order-n Bessel
// function of the second kind
// Using Yn() function
res_1 := math.Yn(-3, -2)
res_2 := math.Yn(6, 3)
res_3 := math.Yn(1, 1.1)
res_4 := math.Yn(1, math.NaN())
res_5 := math.Yn(-1, 0)
// Displaying the result
fmt.Println("Result 1: ", res_1)
fmt.Println("Result 2: ", res_2)
fmt.Println("Result 3: ", res_3)
fmt.Println("Result 4: ", res_4)
fmt.Println("Result 5: ", res_5)
}
输出:
Result 1: NaN
Result 2: -5.436470340703773
Result 3: -0.698119560067667
Result 4: NaN
Result 5: +Inf