温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

golang语言渐入佳境[29]-math包核心方法

发布时间:2020-08-01 15:25:03 来源:网络 阅读:990 作者:jonson_jackson 栏目:开发技术
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main

import (
"fmt"
"math"
)

/*
1、func IsNaN(f float64) (is bool)
 ● 报告f是否表示一个NaN(Not A Number)值。

2、func Ceil(x float64) float64
 ● 返回不小于x的最小整数(的浮点值)

3、func Floor(x float64) float64
 ● 返回不大于x的最小整数(的浮点值)

4、func Trunc(x float64) float64
 ● 返回x的整数部分(的浮点值)。

5、func Abs(x float64) float64
 ● 返回x的绝对值

6、func Max(x, y float64) float64
 ● 返回x和y中最大值

7、func Min(x, y float64) float64
 ● 返回x和y中最小值

8、func Dim(x, y float64) float64
 ● 函数返回x-y和0中的最大值

9、func Mod(x, y float64) float64
 ● 取余运算,可以理解为 x-Trunc(x/y)*y,结果的正负号和x相同

10、func Sqrt(x float64) float64
 ● 返回x的二次方根

11、func Cbrt(x float64) float64
 ● 返回x的三次方根,特例如下:

12、func Hypot(p, q float64) float64
 ● 返回Sqrt(p*p + q*q)

13、func Pow(x, y float64) float64
 ● 返回x^y

14、func Sin(x float64) float64
 ● 求正弦。

15、func Cos(x float64) float64
 ● 求余弦。

16、func Tan(x float64) float64
 ● 求正切。

17、func Log(x float64) float64
 ● 求自然对数

18、func Log2(x float64) float64
 ● 求2为底的对数。

19、func Log10(x float64) float64
求10为底的对数。
*/

func main() {
fmt.Println(math.IsNaN(3.4))      //false
fmt.Println(math.Ceil(1.000001))  //2
fmt.Println(math.Floor(1.999999)) //1
fmt.Println(math.Trunc(1.999999)) //1
fmt.Println(math.Abs(-1.3))       //1.3
fmt.Println(math.Max(-1.3, 0))    //0
fmt.Println(math.Min(-1.3, 0))    //-1.3
fmt.Println(math.Dim(-12, -19))   //7
fmt.Println(math.Dim(-12, 19))    //0
fmt.Println(math.Mod(9, 4))       //1
fmt.Println(math.Sqrt(9))         //3
fmt.Println(math.Cbrt(8))         //2
fmt.Println(math.Hypot(3, 4))     //5
fmt.Println(math.Pow(2, 8))       //256
fmt.Println(math.Log(1))          //0
fmt.Println(math.Log2(16))        //4
fmt.Println(math.Log10(1000))     //3

}
  • 本文链接: https://dreamerjonson.com/2018/12/01/golang-29-math-package/

  • 版权声明: 本博客所有文章除特别声明外,均采用 CC BY 4.0 CN协议 许可协议。转载请注明出处!

golang语言渐入佳境[29]-math包核心方法

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI