Evaluate binomial coefficients: Difference between revisions

Content added Content deleted
m (→‎{{header|Lua}}: add some info on 64bit integer)
m (→‎{{header|Lua}}: handle overflow by switching to double approximate)
Line 1,197:
ans = self(n, n - k)
else
anslocal lhs = self(n-1,k) + self(n-1,k-1)
local rhs = self(n-1,k-1)
local sum = lhs + rhs
if sum<0 or not math.tointeger(sum)then
-- switch to double
ans = lhs/1.0 + rhs/1.0 -- approximate
else
ans = sum
end
end
end
Line 1,205 ⟶ 1,213:
end
})
print( Binomial(100,50)) -- 1.0089134454556e+029
 
</lang>
print( Binomial( 5, 3 ) )
print( Binomial( 5, 4 ) )
print( Binomial(60,30 ) )</lang>
 
=={{header|Liberty BASIC}}==