ADVERTISEMENT
ADVERTISEMENT

Golang math.MaxInt16 Constant with Examples

Golang | math.MaxInt16 Constant: Here, we are going to learn about the MaxInt16 constant of the math package with its usages, syntax, and examples.
Submitted by IncludeHelp, on August 28, 2021

math.MaxInt16 Constant

The MaxInt16 constant is an inbuilt constant of the math package which is used to get the highest (maximum) value that can be represented by an int16.

The value of math.MaxInt16 constants is 1<<15 - 1 or 32767.

Syntax:

int math.MaxInt16

Parameter(s):

  • None

Return Value:

The return type of math.MaxInt16 constant is int, it returns the highest (maximum) value that can be represented by an int16.

Example 1:

// Golang program to demonstrate the
// example of math.MaxInt16 Constant

package main

import (
	"fmt"
	"math"
)

func main() {
	fmt.Printf("Type of math.MaxInt16 is %T\n", math.MaxInt16)
	fmt.Println("Value of math.MaxInt16:", math.MaxInt16)
}

Output:

Type of math.MaxInt16 is int
Value of math.MaxInt16: 32767

Explanation:

In the above program, we imported the math package to use the math.MaxInt16 constant, then printed the type and value of the math.MaxInt16 constant.

Example 2:

// Golang program to demonstrate the
// example of math.MaxInt16 Constant

package main

import (
	"fmt"
	"math"
)

// creating function to
// return the value of MaxInt16.
func getMaxInt16() int {
	return math.MaxInt16
}

func main() {
	fmt.Println("Value of math.MaxInt16:", getMaxInt16())
}

Output:

Value of math.MaxInt16: 32767

Golang math Package Constants and Functions »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.