This commit is contained in:
Araq
2015-09-18 02:22:39 +02:00
parent 1c0b815282
commit a4a5003b7d

View File

@@ -21,6 +21,20 @@ include "system/inclrtl"
{.push debugger:off .} # the user does not want to trace a part
# of the standard library!
proc binom*(n, k: int): int {.noSideEffect.} =
## Computes the binomial coefficient
if k <= 0: return 1
if 2*k > n: return binom(n, n-k)
result = n
for i in countup(2, k):
result = (result * (n + 1 - i)) div i
proc fac*(n: int): int {.noSideEffect.} =
## Computes the faculty/factorial function.
result = 1
for i in countup(2, n):
result = result * i
{.push checks:off, line_dir:off, stack_trace:off.}
when defined(Posix) and not defined(haiku):
@@ -72,21 +86,6 @@ proc classify*(x: float): FloatClass =
return fcNormal
# XXX: fcSubnormal is not detected!
proc binom*(n, k: int): int {.noSideEffect.} =
## Computes the binomial coefficient
if k <= 0: return 1
if 2*k > n: return binom(n, n-k)
result = n
for i in countup(2, k):
result = (result * (n + 1 - i)) div i
proc fac*(n: int): int {.noSideEffect.} =
## Computes the faculty/factorial function.
result = 1
for i in countup(2, n):
result = result * i
proc isPowerOfTwo*(x: int): bool {.noSideEffect.} =
## Returns true, if `x` is a power of two, false otherwise.
## Zero and negative numbers are not a power of two.