溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

golang語(yǔ)言漸入佳境[29]-math包核心方法

發(fā)布時(shí)間:2020-08-01 15:25:03 來(lái)源:網(wǎng)絡(luò) 閱讀:994 作者:jonson_jackson 欄目:開發(fā)技術(shù)
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)
 ● 報(bào)告f是否表示一個(gè)NaN(Not A Number)值。

2、func Ceil(x float64) float64
 ● 返回不小于x的最小整數(shù)(的浮點(diǎn)值)

3、func Floor(x float64) float64
 ● 返回不大于x的最小整數(shù)(的浮點(diǎn)值)

4、func Trunc(x float64) float64
 ● 返回x的整數(shù)部分(的浮點(diǎn)值)。

5、func Abs(x float64) float64
 ● 返回x的絕對(duì)值

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
 ● 函數(shù)返回x-y和0中的最大值

9、func Mod(x, y float64) float64
 ● 取余運(yùn)算,可以理解為 x-Trunc(x/y)*y,結(jié)果的正負(fù)號(hào)和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
 ● 求自然對(duì)數(shù)

18、func Log2(x float64) float64
 ● 求2為底的對(duì)數(shù)。

19、func Log10(x float64) float64
求10為底的對(duì)數(shù)。
*/

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/

  • 版權(quán)聲明: 本博客所有文章除特別聲明外,均采用 CC BY 4.0 CN協(xié)議 許可協(xié)議。轉(zhuǎn)載請(qǐng)注明出處!

golang語(yǔ)言漸入佳境[29]-math包核心方法

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI