Euler's constant 0.5772...: Difference between revisions
Content added Content deleted
(Added a Scheme implementation.) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 34: | Line 34: | ||
=={{header|Burlesque}}== |
=={{header|Burlesque}}== |
||
Subject to double rounding error, evaluates 33 partial terms in a series |
Subject to double rounding error, evaluates 33 partial terms in a series |
||
< |
<syntaxhighlight lang="burlesque">33ro{JroJJJL[\/JL[\/nr\/{-1}\/.*FLJL[ro?^?*\/JL[{2}\/.*FL\/?^?*\/{1.+}m[J{lg}m[\/?/?*++\/1 3.0./\/?^.*}m[++-2 3 2lg.*./.*2lg2./.+</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 42: | Line 42: | ||
=={{header|C}}== |
=={{header|C}}== |
||
===Single precision=== |
===Single precision=== |
||
< |
<syntaxhighlight lang="c">/********************************************* |
||
Subject: Comparing five methods for |
Subject: Comparing five methods for |
||
computing Euler's constant 0.5772... |
computing Euler's constant 0.5772... |
||
Line 162: | Line 162: | ||
printf("\n\nC = 0.57721566490153286...\n"); |
printf("\n\nC = 0.57721566490153286...\n"); |
||
}</ |
}</syntaxhighlight> |
||
{{out|output}} |
{{out|output}} |
||
Line 196: | Line 196: | ||
From first principles |
From first principles |
||
< |
<syntaxhighlight lang="c">/************************************************** |
||
Subject: Computation of Euler's constant 0.5772... |
Subject: Computation of Euler's constant 0.5772... |
||
with the Brent-McMillan algorithm B1, |
with the Brent-McMillan algorithm B1, |
||
Line 373: | Line 373: | ||
tim = clock() - tim; |
tim = clock() - tim; |
||
printf("time: %.7f s\n",((double)tim)/CLOCKS_PER_SEC); |
printf("time: %.7f s\n",((double)tim)/CLOCKS_PER_SEC); |
||
}</ |
}</syntaxhighlight> |
||
{{out|output}} |
{{out|output}} |
||
Line 382: | Line 382: | ||
===The easy way=== |
===The easy way=== |
||
< |
<syntaxhighlight lang="c">/******************************************* |
||
Subject: Euler's constant 0.5772... |
Subject: Euler's constant 0.5772... |
||
tested : tcc-0.9.27 with mpfr 4.1.0 |
tested : tcc-0.9.27 with mpfr 4.1.0 |
||
Line 409: | Line 409: | ||
tim = clock() - tim; |
tim = clock() - tim; |
||
gmp_printf ("time: %.7f s\n",((double)tim)/CLOCKS_PER_SEC); |
gmp_printf ("time: %.7f s\n",((double)tim)/CLOCKS_PER_SEC); |
||
}</ |
}</syntaxhighlight> |
||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
===Single precision=== |
===Single precision=== |
||
< |
<syntaxhighlight lang="freebasic">'********************************************** |
||
'Subject: Comparing five methods for |
'Subject: Comparing five methods for |
||
' computing Euler's constant 0.5772... |
' computing Euler's constant 0.5772... |
||
Line 533: | Line 533: | ||
? |
? |
||
? "C = 0.57721566490153286..." |
? "C = 0.57721566490153286..." |
||
end</ |
end</syntaxhighlight> |
||
{{out|output}} |
{{out|output}} |
||
Line 566: | Line 566: | ||
===Multi precision=== |
===Multi precision=== |
||
From first principles |
From first principles |
||
< |
<syntaxhighlight lang="freebasic">'*************************************************** |
||
'Subject: Computation of Euler's constant 0.5772... |
'Subject: Computation of Euler's constant 0.5772... |
||
' with the Brent-McMillan algorithm B1, |
' with the Brent-McMillan algorithm B1, |
||
Line 737: | Line 737: | ||
gmp_printf (!"time: %.7f s\n", TIMER - tim) |
gmp_printf (!"time: %.7f s\n", TIMER - tim) |
||
end</ |
end</syntaxhighlight> |
||
{{out|output}} |
{{out|output}} |
||
Line 746: | Line 746: | ||
===The easy way=== |
===The easy way=== |
||
< |
<syntaxhighlight lang="freebasic">' ****************************************** |
||
'Subject: Euler's constant 0.5772... |
'Subject: Euler's constant 0.5772... |
||
'tested : FreeBasic 1.08.1 with mpfr 4.1.0 |
'tested : FreeBasic 1.08.1 with mpfr 4.1.0 |
||
Line 768: | Line 768: | ||
gmp_printf (!"time: %.7f s\n", TIMER - tim) |
gmp_printf (!"time: %.7f s\n", TIMER - tim) |
||
end</ |
end</syntaxhighlight> |
||
Line 776: | Line 776: | ||
'''Works with gojq, the Go implementation of jq''' |
'''Works with gojq, the Go implementation of jq''' |
||
< |
<syntaxhighlight lang="jq"># Bailey, 1988 |
||
def bailey($n; $eps): |
def bailey($n; $eps): |
||
pow(2; $n) as $n2 |
pow(2; $n) as $n2 |
||
Line 786: | Line 786: | ||
| .b = .a |
| .b = .a |
||
| .a += (.r * .h) ) |
| .a += (.r * .h) ) |
||
| (.a * $n2 / ($n2|exp) ) - ($n * (2|log)) ;</ |
| (.a * $n2 / ($n2|exp) ) - ($n * (2|log)) ;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 795: | Line 795: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
{{trans|PARI/GP}} |
{{trans|PARI/GP}} |
||
< |
<syntaxhighlight lang="julia">display(MathConstants.γ) # γ = 0.5772156649015... |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
<lang |
<syntaxhighlight lang="mathematica">N[EulerGamma, 1000]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>0.57721566490153286060651209008240243104215933593992359880576723488486772677766467093694706329174674 |
<pre>0.57721566490153286060651209008240243104215933593992359880576723488486772677766467093694706329174674 |
||
Line 813: | Line 813: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">import std/math |
||
const n = 1e6 |
const n = 1e6 |
||
Line 822: | Line 822: | ||
echo result - ln(n) |
echo result - ln(n) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 830: | Line 830: | ||
=={{header|PARI/GP}}== |
=={{header|PARI/GP}}== |
||
built-in: |
built-in: |
||
< |
<syntaxhighlight lang="parigp">\l "euler_const.log" |
||
\p 100 |
\p 100 |
||
print("gamma ", Euler); |
print("gamma ", Euler); |
||
\q</ |
\q</syntaxhighlight> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
< |
<syntaxhighlight lang="perl">#!/usr/bin/perl |
||
use strict; # https://en.wikipedia.org/wiki/Euler%27s_constant |
use strict; # https://en.wikipedia.org/wiki/Euler%27s_constant |
||
Line 842: | Line 842: | ||
use List::Util qw( sum ); |
use List::Util qw( sum ); |
||
print sum( map 1 / $_, 1 .. 1e6) - log 1e6, "\n";</ |
print sum( map 1 / $_, 1 .. 1e6) - log 1e6, "\n";</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 851: | Line 851: | ||
===part 1 (max 12dp)=== |
===part 1 (max 12dp)=== |
||
Translation of Perl, with the same accuracy limitation |
Translation of Perl, with the same accuracy limitation |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Eulers_constant.exw</span> |
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Eulers_constant.exw</span> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
||
<span style="color: #008080;">constant</span> <span style="color: #000000;">C</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sum</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sq_div</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1e6</span><span style="color: #0000FF;">)))-</span><span style="color: #7060A8;">log</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1e6</span><span style="color: #0000FF;">)</span> |
<span style="color: #008080;">constant</span> <span style="color: #000000;">C</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sum</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sq_div</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1e6</span><span style="color: #0000FF;">)))-</span><span style="color: #7060A8;">log</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1e6</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"gamma %.12f (max 12d.p. of accuracy)\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">C</span><span style="color: #0000FF;">)</span> |
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"gamma %.12f (max 12d.p. of accuracy)\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">C</span><span style="color: #0000FF;">)</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 863: | Line 863: | ||
===part 2 (first principles)=== |
===part 2 (first principles)=== |
||
Translation of C, from first principles. |
Translation of C, from first principles. |
||
<!--< |
<!--<syntaxhighlight lang="phix">--> |
||
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- no mpfr_get_d_2exp() in mpfr.js as yet</span> |
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- no mpfr_get_d_2exp() in mpfr.js as yet</span> |
||
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"1.0.2"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- mpfr_get_d_2exp(), mpfr_addmul_si()</span> |
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"1.0.2"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- mpfr_get_d_2exp(), mpfr_addmul_si()</span> |
||
Line 951: | Line 951: | ||
<span style="color: #004080;">string</span> <span style="color: #000000;">su</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mpfr_get_fixed</span><span style="color: #0000FF;">(</span><span style="color: #000000;">u</span><span style="color: #0000FF;">,</span><span style="color: #000000;">e10</span><span style="color: #0000FF;">)</span> |
<span style="color: #004080;">string</span> <span style="color: #000000;">su</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mpfr_get_fixed</span><span style="color: #0000FF;">(</span><span style="color: #000000;">u</span><span style="color: #0000FF;">,</span><span style="color: #000000;">e10</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"gamma %s (maxerr. 1e-%d)\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">su</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">e10</span><span style="color: #0000FF;">})</span> |
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"gamma %s (maxerr. 1e-%d)\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">su</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">e10</span><span style="color: #0000FF;">})</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 957: | Line 957: | ||
</pre> |
</pre> |
||
===part 3 (the easy way)=== |
===part 3 (the easy way)=== |
||
<!--< |
<!--<syntaxhighlight lang="phix">--> |
||
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- no mpfr_const_euler() in mpfr.js as yet</span> |
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- no mpfr_const_euler() in mpfr.js as yet</span> |
||
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"1.0.1"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- mpfr_const_euler()</span> |
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"1.0.1"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- mpfr_const_euler()</span> |
||
Line 964: | Line 964: | ||
<span style="color: #000000;">mpfr_const_euler</span><span style="color: #0000FF;">(</span><span style="color: #000000;">gamma</span><span style="color: #0000FF;">)</span> |
<span style="color: #000000;">mpfr_const_euler</span><span style="color: #0000FF;">(</span><span style="color: #000000;">gamma</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"gamma %s (mpfr_const_euler)\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">mpfr_get_fixed</span><span style="color: #0000FF;">(</span><span style="color: #000000;">gamma</span><span style="color: #0000FF;">,</span><span style="color: #000000;">100</span><span style="color: #0000FF;">)})</span> |
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"gamma %s (mpfr_const_euler)\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">mpfr_get_fixed</span><span style="color: #0000FF;">(</span><span style="color: #000000;">gamma</span><span style="color: #0000FF;">,</span><span style="color: #000000;">100</span><span style="color: #0000FF;">)})</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
<small>(matches part 2 except for the 100th decimal place)</small> |
<small>(matches part 2 except for the 100th decimal place)</small> |
||
{{out}} |
{{out}} |
||
Line 973: | Line 973: | ||
=={{header|Picat}}== |
=={{header|Picat}}== |
||
===List comprehension=== |
===List comprehension=== |
||
< |
<syntaxhighlight lang="picat">main => |
||
Gamma = 0.57721566490153286060651209008240, |
Gamma = 0.57721566490153286060651209008240, |
||
println(Gamma), |
println(Gamma), |
||
Line 981: | Line 981: | ||
end. |
end. |
||
e(N) = [1.0/I : I in 1..N].sum-log(N).</ |
e(N) = [1.0/I : I in 1..N].sum-log(N).</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 995: | Line 995: | ||
===Loop=== |
===Loop=== |
||
< |
<syntaxhighlight lang="picat">e2(N) = E-log(N) => |
||
E = 1, |
E = 1, |
||
foreach(I in 2..N) |
foreach(I in 2..N) |
||
E := E + 1/I |
E := E + 1/I |
||
end.</ |
end.</syntaxhighlight> |
||
{{trans|Rust}} |
{{trans|Rust}} |
||
< |
<syntaxhighlight lang="picat">main => |
||
Gamma = 0.577215664901532860606512090082402, |
Gamma = 0.577215664901532860606512090082402, |
||
println(gamma=Gamma), |
println(gamma=Gamma), |
||
Line 1,023: | Line 1,023: | ||
end, |
end, |
||
Gamma := Gamma + I*Term |
Gamma := Gamma + I*Term |
||
end.</ |
end.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,053: | Line 1,053: | ||
=={{header|Processing}}== |
=={{header|Processing}}== |
||
{{trans|C}} |
{{trans|C}} |
||
<syntaxhighlight lang="processing"> |
|||
<lang Processing> |
|||
/********************************************* |
/********************************************* |
||
Subject: Comparing five methods for |
Subject: Comparing five methods for |
||
Line 1,199: | Line 1,199: | ||
println("C = 0.57721566490153286...\n"); |
println("C = 0.57721566490153286...\n"); |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,235: | Line 1,235: | ||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
< |
<syntaxhighlight lang="racket">#lang racket/base |
||
(require math/number-theory |
(require math/number-theory |
||
Line 1,253: | Line 1,253: | ||
(/ (bernoulli-number 2k) (* (expt n 2k) 2k))))) |
(/ (bernoulli-number 2k) (* (expt n 2k) 2k))))) |
||
(g)</ |
(g)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,260: | Line 1,260: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
<lang |
<syntaxhighlight lang="raku" line># 20211124 Raku programming solution |
||
sub gamma (\N where N > 1) { # Vacca series https://w.wiki/4ybp |
sub gamma (\N where N > 1) { # Vacca series https://w.wiki/4ybp |
||
Line 1,274: | Line 1,274: | ||
} |
} |
||
say gamma 23 ;</ |
say gamma 23 ;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,281: | Line 1,281: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
< |
<syntaxhighlight lang="ruby">n = 1e6 |
||
p (1..n).sum{ 1.0/_1 } - Math.log(n)</ |
p (1..n).sum{ 1.0/_1 } - Math.log(n)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>0.5772161649014507 #12 digits accurate |
<pre>0.5772161649014507 #12 digits accurate |
||
Line 1,289: | Line 1,289: | ||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang="rust">// 20220322 Rust programming solution |
||
fn gamma(N: u32) -> f64 { // Vacca series https://w.wiki/4ybp |
fn gamma(N: u32) -> f64 { // Vacca series https://w.wiki/4ybp |
||
Line 1,311: | Line 1,311: | ||
fn main() { |
fn main() { |
||
println!("{}", gamma(23)); |
println!("{}", gamma(23)); |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>0.5772149198434514</pre> |
<pre>0.5772149198434514</pre> |
||
=={{header|Scheme}}== |
=={{header|Scheme}}== |
||
{{works with|Chez Scheme}} |
{{works with|Chez Scheme}} |
||
< |
<syntaxhighlight lang="scheme">; Procedure to compute factorial. |
||
(define fact |
(define fact |
||
(lambda (n) |
(lambda (n) |
||
Line 1,333: | Line 1,333: | ||
; Show Euler's gamma constant computed at log(100). |
; Show Euler's gamma constant computed at log(100). |
||
(printf "Euler's gamma constant: ~a~%" (gamma 100))</ |
(printf "Euler's gamma constant: ~a~%" (gamma 100))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,341: | Line 1,341: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
Built-in: |
Built-in: |
||
< |
<syntaxhighlight lang="ruby"># 100 decimals of precision |
||
local Num!PREC = 4*100 |
local Num!PREC = 4*100 |
||
say Num.EulerGamma</ |
say Num.EulerGamma</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,350: | Line 1,350: | ||
Several formulas: |
Several formulas: |
||
< |
<syntaxhighlight lang="ruby">const n = (ARGV ? Num(ARGV[0]) : 50) # number of iterations |
||
define ℯ = Num.e |
define ℯ = Num.e |
||
Line 1,400: | Line 1,400: | ||
display(sum(1..n, {|n| |
display(sum(1..n, {|n| |
||
(-1)**n * floor(log2(n)) / n |
(-1)**n * floor(log2(n)) / n |
||
}), γ)</ |
}), γ)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,416: | Line 1,416: | ||
=={{header|Vlang}}== |
=={{header|Vlang}}== |
||
{{trans|C}} |
{{trans|C}} |
||
< |
<syntaxhighlight lang="vlang">import math |
||
const eps = 1e-6 |
const eps = 1e-6 |
||
fn main() { |
fn main() { |
||
Line 1,513: | Line 1,513: | ||
println("err ${a:0.16f}\ngamma ${h+a:0.16f}\nk = ${n+m}") |
println("err ${a:0.16f}\ngamma ${h+a:0.16f}\nk = ${n+m}") |
||
println("\nC = 0.57721566490153286...") |
println("\nC = 0.57721566490153286...") |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Same as C entry</pre> |
<pre>Same as C entry</pre> |
||
Line 1,522: | Line 1,522: | ||
{{libheader|Wren-fmt}} |
{{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. |
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="ecmascript">import "./fmt" for Fmt |
||
var eps = 1e-6 |
var eps = 1e-6 |
||
Line 1,608: | Line 1,608: | ||
} |
} |
||
Fmt.print("err $0.14f\ngamma $0.14f\nk = $d", a, h + a, n + m) |
Fmt.print("err $0.14f\ngamma $0.14f\nk = $d", a, h + a, n + m) |
||
System.print("\nC = 0.57721566490153286...")</ |
System.print("\nC = 0.57721566490153286...")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,642: | Line 1,642: | ||
{{libheader|Wren-gmp}} |
{{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. |
The display is limited to 100 digits for all four examples as I couldn't see much point in showing them all. |
||
< |
<syntaxhighlight lang="ecmascript">import "./gmp" for Mpf |
||
var euler = Fn.new { |n, r, s, t| |
var euler = Fn.new { |n, r, s, t| |
||
Line 1,685: | Line 1,685: | ||
euler.call(9375, 91, 68, 40) |
euler.call(9375, 91, 68, 40) |
||
euler.call(18750, 98, 73, 43) |
euler.call(18750, 98, 73, 43) |
||
System.print("\nTook %(System.clock - start) seconds.")</ |
System.print("\nTook %(System.clock - start) seconds.")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,701: | Line 1,701: | ||
</pre> |
</pre> |
||
===The easy way (Embedded)=== |
===The easy way (Embedded)=== |
||
< |
<syntaxhighlight lang="ecmascript">import "./gmp" for Mpf |
||
var prec = (101/0.30103).round |
var prec = (101/0.30103).round |
||
var gamma = Mpf.euler(prec) |
var gamma = Mpf.euler(prec) |
||
System.print(gamma.toString(10, 100))</ |
System.print(gamma.toString(10, 100))</syntaxhighlight> |
||
{{out}} |
{{out}} |