Mod()
function is used to find the floating-point remainder of x/y
. The magnitude of the result is less than y and its sign agrees with that of x
. The standard math package of Go programming language has Mod()
function.
Syntax of Mod()
Function in Go
The syntax of Mod()
function in Go Language is:
func Mod(x, y float64) float64
Note: float64
is a data type in Go language which has IEEE-754 64-bit floating-point numbers.
Special cases are:
Mod(±Inf, y) = NaN
Mod(NaN, y) = NaN
Mod(x, 0) = NaN
Mod(x, ±Inf) = x
Mod(x, NaN) = NaN
Parameters of Mod()
Function in Go Language
x, y
– Where x
and y
are Valid float64
Input valued. These parameters are required.
Error Handling
If the
If there is no argument (
x
or y
parameter are not number (numeric values) Mod()
function returns an error
.If there is no argument (
x
or y
– input values) passes to the function, then the compiler will produce an error
.
Return Value of Mod()
Function in Go
Mod()
function will 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
.
GoLang Mod()
Function Example 1
package main import "fmt" import "math" func main() { var x float64 x = math.Mod(-8, 66) fmt.Println(x) }
Output:
-8
GoLang Mod()
Function Example 2
package main import "fmt" import "math" func main() { var x float64 x = math.Mod(7, 4) fmt.Println(x) }
Output:
3
GoLang Mod()
Function Example 3
package main import "fmt" import "math" func main() { var x float64 x = math.Mod(-8, -3.4) fmt.Println(x) }
Output:
-1.2000000000000002