Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

GoLang – Find the floating-point remainder – Mod() Function – Examples & Explanation

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:

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 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


Output:
-8

 

GoLang Mod() Function Example 2


Output:
3

 

GoLang Mod() Function Example 3


Output:
-1.2000000000000002

 

Loading...
LearnAndLearn.com © 2018 - All rights reserved