Jump to content

Euler's constant 0.5772...: Difference between revisions

Add Scala implementation
m (→‎{{header|Wren}}: Changed to Wren S/H)
(Add Scala implementation)
Line 1,726:
<pre>
Euler's gamma constant: 0.5772156649015328
</pre>
 
=={{header|Scala}}==
<syntaxhighlight lang="Scala">
/**
* Using a simple 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: 0.57721566490...
*/
 
object EulerConstant extends App {
 
println(gamma(1_000_000))
 
private def gamma(N: Int): Double = {
val sumOverN = (1 to N).map(1.0 / _).sum
sumOverN - Math.log(N) - 1.0 / (2 * N)
}
 
}
</syntaxhighlight>
{{out}}
<pre>
0.5772156649007153
</pre>
 
338

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.