ADVERTISEMENT
ADVERTISEMENT

Golang math.Sqrt2 Constant with Examples

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

math.Sqrt2 Constant

The Sqrt2 constant is an inbuilt constant of the math package which is used to get the square root of 2, approximately equal to 1.414.

Syntax:

float64 math.Sqrt2

Parameter(s):

  • None

Return Value:

The return type of math.Sqrt2 constant is float64, it returns the square root of 2.

Example 1:

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

package main

import (
	"fmt"
	"math"
)

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

Output:

Type of math.Sqrt2 is float64
Value of math.Sqrt2: 1.4142135623730951

Explanation:

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

Example 2:

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

package main

import (
	"fmt"
	"math"
)

// creating function to return 
// the value of Sqrt2.
func getSqrt2() float64 {
	return math.Sqrt2
}

func main() {
	fmt.Println("Value of math.Sqrt2:", getSqrt2())
}

Output:

Value of math.Sqrt2: 1.4142135623730951

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.