From c0c4a7d6a649e9934530364893228fa65d787991 Mon Sep 17 00:00:00 2001 From: apense Date: Thu, 18 Jun 2015 16:07:00 -0400 Subject: Added some C99 funcs Error function (and complementary) and gamma function (and truncated) --- lib/pure/math.nim | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/pure/math.nim b/lib/pure/math.nim index b91c7f0d8..494dfc4c8 100644 --- a/lib/pure/math.nim +++ b/lib/pure/math.nim @@ -161,6 +161,8 @@ proc randomize*(seed: int) {.benign.} when not defined(JS): proc sqrt*(x: float): float {.importc: "sqrt", header: "".} ## computes the square root of `x`. + proc cbrt*(x: float): float {.importc: "cbrt", header: "".} + ## computes the cubic root of `x` proc ln*(x: float): float {.importc: "log", header: "".} ## computes ln(x). @@ -200,6 +202,16 @@ when not defined(JS): proc tanh*(x: float): float {.importc: "tanh", header: "".} proc pow*(x, y: float): float {.importc: "pow", header: "".} ## computes x to power raised of y. + + proc erf*(x: float): float {.importc: "erf", header: "".} + ## The error function + proc erfc*(x: float): float {.importc: "erfc", header: "".} + ## The complementary error function + + proc lgamma*(x: float): float {.importc: "lgamma", header: "".} + ## Natural log of the gamma function + proc tgamma*(x: float): float {.importc: "tgamma", header: "".} + ## The gamma function # C procs: when defined(vcc): @@ -411,3 +423,9 @@ when isMainModule and not defined(JS): # Check for no side effect annotation proc mySqrt(num: float): float {.noSideEffect.} = return sqrt(num) + + # check gamma function + assert(tgamma(5.0) == 24.0) # 4! + assert(lgamma(1.0) == 0.0) # ln(1.0) == 0.0 + assert(erf(6.0) > erf(5.0)) + assert(erfc(6.0) < erfc(5.0)) -- cgit 1.4.1-2-gfad0