Gamma function: Difference between revisions

Content deleted Content added
Tikkanz (talk | contribs)
m →‎{{header|J}}: fix links and tags
Line 579:
This code shows the built-in method, which works for any value (positive, negative and complex numbers).
 
<lang Jj>gamma=: !@<:</lang>
gamma=. !@<:
</lang>
 
The following direct coding of the task comes from httpthe [[J://www.jsoftware.com/jwiki/Essays/Stirling's%20Approximation|Stirling's approximation essay]] on the J wiki (copyright issues ignored, since this is simple math):
 
<lang Jj>sbase =: %:@(2p1&%) * %&1x1 ^ ]
scorr =: 1 1r12 1r288 _139r51840 _571r2488320&p.@%
stirlg=: sbase * scorr</lang>
 
Checking against <code>!@<:</code> we can see that this approximation loses accuracy for small arguments
 
<lang j> (,. stirlg ,. !@<:gamma) 10 1p1 1x1 1.5 1
10 362880 362880
3.14159 2.28803 2.28804
2.71828 1.56746 1.56747
1.5 0.886155 0.886227
1 0.999499 1</lang>
 
=={{header|Mathematica}}==