Is there a defined value in the standard namespaces for the golden ratio?

The Math.Net library contains a definition for the GoldenRatio, and its implementation matches the answer from @Steve above. It also includes a large number of other useful math-related functionality.


No it isn't an already defined value for golden ratio. You have to build a method for the calculation of the golden ratio or you could declare a const variable, in which you will store this value.

const double goldenRatio = 1.61803398874989484820458683436;

No there is not. However, the golden ratio is the solution to a number whose reciprocal is itself minus 1:

$\dfrac{1}{x} = x - 1\ \longrightarrow\ x^2 - x - 1 = 0$

You can then solve that with the quadratic formula to get:

$\dfrac{1+\sqrt{5}}{2} = 1.61803398874989484820458683436\mathellipsis$

This means you can define the golden ratio as one of the following:

readonly double GoldenRatio = (1 + Math.Sqrt(5)) / 2;
const double GoldenRatio = 1.61803398874989484820458683436;

Tags:

C#