×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang math.Phi Constant with Examples

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

math.Phi Constant

The Phi constant is an inbuilt constant of the math package which is used to get the value of mathematical constant φ (Golden Ratio). The number φ also called the golden ratio, turns up frequently in geometry, particularly in figures with pentagonal symmetry. Indeed, the length of a regular pentagon's diagonal is φ times its side.

Syntax

float64 math.Phi

Parameters

  • None

Return Value

The return type of math.Phi constant is float64, it returns the value of mathematical constant φ.

Example 1

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

package main

import (
	"fmt"
	"math"
)

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

Output:

Type of math.Phi is float64
Value of math.Phi: 1.618033988749895

Explanation:

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

Example 2

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

package main

import (
	"fmt"
	"math"
)

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

func main() {
	fmt.Println("Value of math.Phi:", getPhi())
}

Output:

Value of math.Phi: 1.618033988749895

Golang math Package Constants and Functions »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.