分享
  1. 首页
  2. 文章

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

jonson_jackson · · 6471 次点击 · · 开始浏览
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

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

}

image.png


有疑问加站长微信联系(非本文作者)

本文来自:51CTO博客

感谢作者:jonson_jackson

查看原文:golang语言渐入佳境[29]-math包核心方法

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

关注微信
6471 次点击
被以下专栏收入,发现更多相似内容
暂无回复
添加一条新回复 (您需要 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传

用户登录

没有账号?注册
(追記) (追記ここまで)

今日阅读排行

    加载中
(追記) (追記ここまで)

一周阅读排行

    加载中

关注我

  • 扫码关注领全套学习资料 关注微信公众号
  • 加入 QQ 群:
    • 192706294(已满)
    • 731990104(已满)
    • 798786647(已满)
    • 729884609(已满)
    • 977810755(已满)
    • 815126783(已满)
    • 812540095(已满)
    • 1006366459(已满)
    • 692541889

  • 关注微信公众号
  • 加入微信群:liuxiaoyan-s,备注入群
  • 也欢迎加入知识星球 Go粉丝们(免费)

给该专栏投稿 写篇新文章

每篇文章有总共有 5 次投稿机会

收入到我管理的专栏 新建专栏