Home »
Golang »
Golang Reference
Golang math.MaxInt64 Constant with Examples
Golang | math.MaxInt64 Constant: Here, we are going to learn about the MaxInt64 constant of the math package with its usages, syntax, and examples.
Submitted by IncludeHelp, on August 28, 2021
math.MaxInt64 Constant
The MaxInt64 constant is an inbuilt constant of the math package which is used to get the highest (maximum) value that can be represented by an int64.
The value of math.MaxInt64 constants is 1<<63 - 1 or 9223372036854775807.
Syntax
int math.MaxInt64
Parameters
Return Value
The return type of math.MaxInt64 constant is int, it returns the highest (maximum) value that can be represented by an int64.
Example 1
// Golang program to demonstrate the
// example of math.MaxInt64 Constant
package main
import (
"fmt"
"math"
)
func main() {
fmt.Printf("Type of math.MaxInt64 is %T\n", math.MaxInt64)
fmt.Println("Value of math.MaxInt64:", math.MaxInt64)
}
Output:
Type of math.MaxInt64 is int
Value of math.MaxInt64: 9223372036854775807
Explanation:
In the above program, we imported the math package to use the math.MaxInt64 constant, then printed the type and value of the math.MaxInt64 constant.
Example 2
// Golang program to demonstrate the
// example of math.MaxInt64 Constant
package main
import (
"fmt"
"math"
)
// creating function to
// return the value of MaxInt64.
func getMaxInt64() int {
return math.MaxInt64
}
func main() {
fmt.Println("Value of math.MaxInt64:", getMaxInt64())
}
Output:
Value of math.MaxInt64: 9223372036854775807
Golang math Package Constants and Functions »