go Mod(),取余运算

Mod()方法语法

func Mod(x, y float64) float64

go源码对Mod()方法的介绍:

Mod returns the floating-point remainder of x/y. The magnitude of the result is less than y and its sign agrees with that of x.

Special cases are:

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

golang的math.Mod()方法,接收x,y两个float64类型的参数,可用于取余运算,相当于 x-Trunc(x/y)*y,正负号与x的相同。除此之外,Mod(±Inf, y) = NaN;Mod(NaN, y) = NaN;Mod(x, 0) = NaN;Mod(x, ±Inf) = x;Mod(x, NaN) = NaN。


math.Mod()方法实例代码

func main() {
	var mod_num float64 = math.Mod(11, 6)
	fmt.Println(mod_num)
}

运行go文件,得到输出:

5

全栈后端 / go语法 :













Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.