Euler's constant 0.5772...: Difference between revisions
Content added Content deleted
Tag: Manual revert |
|||
Line 881: | Line 881: | ||
<syntaxhighlight lang=J> Euler |
<syntaxhighlight lang=J> Euler |
||
0.5772156649015329</syntaxhighlight> |
0.5772156649015329</syntaxhighlight> |
||
=={{header|Java}}== |
|||
<syntaxhighlight> |
|||
/** |
|||
* Using a formula derived from Hurwitz zeta function, |
|||
* as described on https://en.wikipedia.org/wiki/Euler%27s_constant, |
|||
* gives a result accurate to 11 decimal places. |
|||
*/ |
|||
public class EulerConstant { |
|||
public static void main(String[] args) { |
|||
System.out.println(gamma(1_000_000)); |
|||
} |
|||
private static double gamma(int N) { |
|||
double gamma = 0.0; |
|||
for ( int n = 1; n <= N; n++ ) { |
|||
gamma += 1.0 / n; |
|||
} |
|||
gamma -= Math.log(N) + 1.0 / ( 2 * N ); |
|||
return gamma; |
|||
} |
|||
} |
|||
</syntaxhighlight> |
|||
=={{header|jq}}== |
=={{header|jq}}== |