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

Added Easylang
No edit summary
(Added Easylang)
 
(7 intermediate revisions by 6 users not shown)
Line 863:
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
This programs demonstrates the basic method of calculating the Euler number. It illustrates how the number of iterations increaseincreases the accuracy.
<syntaxhighlight lang="Delphi">
 
Line 950:
</pre>
 
 
=={{header|EasyLang}}==
<syntaxhighlight>
fastfunc gethn n .
i = 1
while i <= n
hn += 1 / i
i += 1
.
return hn
.
e = 2.718281828459045235
n = 10e8
numfmt 9 0
print gethn n - log10 n / log10 e
</syntaxhighlight>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
void local fn Euler
long n = 10000000, k
double a, h = 1.0
for k = 2 to n
h += 1 / k
next
a = log( n + 0.5 + 1 / ( 24 * n ) )
printf @"From the definition, err. 3e-10"
printf @"Hn %.15f", h
printf @"gamma %.15f", h - a
printf @"k = %ld\n", n
printf @"C %.15f", 0.5772156649015328
end fn
 
CFTimeInterval t
t = fn CACurrentMediaTime
fn Euler
printf @"\vCompute time: %.3f ms",(fn CACurrentMediaTime-t)*1000
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
From the definition, err. 3e-10
Hn 16.695311365857272
gamma 0.577215664898954
k = 10000000
 
C 0.577215664901533
Compute time: 67.300 ms
</pre>
 
=={{header|J}}==
Line 1,102 ⟶ 1,154:
8328690001558193988042707411542227819716523011073565833967348717650491941812300040654693142999297779
569303100503086303418569803231083691640025892970890985486825777364288253954925873629596133298574739302</pre>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
%gamma,numer;
</syntaxhighlight>
{{out}}
<pre>
0.5772156649015329
</pre>
 
=={{header|Nim}}==
Line 1,592 ⟶ 1,653:
<pre>
0.5772149198434515
</pre>
 
=={{header|RPL}}==
{{trans|FreeBASIC}}
'''From the definition, with Negoi's convergence improvement'''
≪ → n
≪ 1
2 n '''FOR''' k k INV + '''NEXT'''
n .5 + 24 n * INV + LN -
≫ ≫ ‘<span style="color:blue">GAMMA1</span>’ STO
'''Sweeney method'''
≪ 0 OVER R→C 1E-6 → n s eps
≪ n 1
'''DO'''
1 + SWAP
OVER / n * SWAP
DUP2 /
IF OVER 2 MOD THEN (0,1) * END 's' STO+
'''UNTIL''' OVER eps < '''END'''
DROP2
s C→R SWAP - n LN -
≫ ≫ ‘<span style="color:blue">GAMMA2</span>’ STO
 
400 <span style="color:blue">GAMMA1</span>
21 <span style="color:blue">GAMMA2</span>
{{out}}
<pre>
2: .57721566456
1: .57717756228
</pre>
 
Line 1,628 ⟶ 1,718:
{{out}}
<pre>0.5772149198434514</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>
 
=={{header|Scheme}}==
{{works with|Chez Scheme}}
Line 1,652 ⟶ 1,767:
Euler's gamma constant: 0.5772156649015328
</pre>
 
 
 
=={{header|Sidef}}==
Line 1,836 ⟶ 1,953:
{{libheader|Wren-fmt}}
Note that, whilst internally double arithmetic is carried out to the same precision as C (Wren is written in C), printing doubles is effectively limited to a maximum of 14 decimal places.
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
var eps = 1e-6
Line 1,956 ⟶ 2,073:
{{libheader|Wren-gmp}}
The display is limited to 100 digits for all four examples as I couldn't see much point in showing them all.
<syntaxhighlight lang="ecmascriptwren">import "./gmp" for Mpf
 
var euler = Fn.new { |n, r, s, t|
Line 2,015 ⟶ 2,132:
</pre>
===The easy way (Embedded)===
<syntaxhighlight lang="ecmascriptwren">import "./gmp" for Mpf
 
var prec = (101/0.30103).round
2,056

edits