ADVERTISEMENT
ADVERTISEMENT

Golang math.MinInt Constant with Examples

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

math.MinInt Constant

The MinInt constant is an inbuilt constant of the math package which is used to get the lowest (minimum) value that can be represented by an int.

The value of math.MinInt constants is -1 << (intSize - 1).

Note: intSize depends on the machine architecture. For example, if the machine is a 32-bit machine, intSize will be 4 bytes and if the machine is 64-bit, intSize will be 8 bytes.

Syntax:

int math.MinInt

Parameter(s):

  • None

Return Value:

The return type of math.MinInt constant is int, it returns the lowest (minimum) value that can be represented by an int.

Example 1:

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

package main

import (
	"fmt"
	"math"
)

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

Output:

Type of math.MinInt is int
Value of math.MinInt: -9223372036854775808

Explanation:

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

Example 2:

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

package main

import (
	"fmt"
	"math"
)

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

func main() {
	fmt.Println("Value of math.MinInt:", getMinInt())
}

Output:

Value of math.MinInt: -9223372036854775808

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.