Jump to content

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

Added a Scheme implementation.
(Added a Scheme implementation.)
Line 1,314:
{{out}}
<pre>0.5772149198434514</pre>
=={{header|Scheme}}==
{{works with|Chez Scheme}}
<lang scheme>; Procedure to compute factorial.
(define fact
(lambda (n)
(if (<= n 0)
1
(* n (fact (1- n))))))
 
; Compute Euler's gamma constant as the difference of log(n) from a sum.
; See section 2.3 of <http://numbers.computation.free.fr/Constants/Gamma/gamma.html>.
(define gamma
(lambda (n)
(let ((sum 0))
(do ((k 1 (1+ k)))
((> k (* 3.5911 n)) (- sum (log n)))
(set! sum (+ sum (/ (* (expt -1 (1- k)) (expt n k)) (* k (fact k)))))))))
 
; Show Euler's gamma constant computed at log(100).
(printf "Euler's gamma constant: ~a~%" (gamma 100))</lang>
{{out}}
<pre>
Euler's gamma constant: 0.5772156649015328
</pre>
 
=={{header|Sidef}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.