Learn and Learn

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

GoLang – Find maximum value – Max() Function – Examples & Explanation

Max() function is used to find the larger of x or y the given inputs (x or y – parameters) in Go language. The standard math package of Go programming language has Max() function.

Syntax of Max() Function in Go Language

The syntax of Max() 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:
Max(x, +Inf) = Max(+Inf, x) = +Inf
Max(x, NaN) = Max(NaN, x) = NaN
Max(+0, ±0) = Max(±0, +0) = +0
Max(-0, -0) = -0

 

Parameters of Max() Function in Go Language

x – Where x or y are Valid float64 Input value. These parameters are required.

 

Error Handling

If the x or y parameter is not a number (numeric value) Max() function returns an error .
If there are no arguments (x or y – input values) passes to the function, then the compiler will produce an error.

 

Return Value of Max() Function in Go Language

Max() function will return the larger of x or y the given inputs (x or y – parameters).

 

GoLang Max() Function Example 1


Output:
7

 

GoLang Max() Function Example 2


Output:
10

 

GoLang Max() Function Example 3


Output:
-8

 

LearnAndLearn.com © 2018 - All rights reserved