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