Skip to content
Permalink
Browse files

First stab at Math.lgamma

  • Loading branch information
Alex Gaynor
Alex Gaynor committed Apr 10, 2013
1 parent c9b9a2f commit 0ece2b84a1679d402bbc271e0a4865bb1eb009e7
Showing with 10 additions and 7 deletions.
  1. +0 −7 spec/tags/core/math/lgamma_tags.txt
  2. +10 −0 topaz/modules/math.py
@@ -1,9 +1,2 @@
fails:Math.lgamma returns [Infinity, 1] when passed 0
fails:Math.lgamma returns [Infinity, 1] when passed -1
fails:Math.lgamma returns [log(sqrt(PI)), 1] when passed 0.5
fails:Math.lgamma returns [log(2/3*PI, 1] when passed 6.0
fails:Math.lgamma returns an approximate value when passed -0.5
fails:Math.lgamma returns an approximate value when passed -1.5
fails:Math.lgamma raises Math::DomainError when passed -Infinity
fails:Math.lgamma returns [Infinity, 1] when passed Infinity
fails:Math.lgamma returns [NaN, 1] when passed NaN
@@ -101,6 +101,16 @@ def method_gamma(self, space, value):
res = rfloat.INFINITY
return space.newfloat(res)

@moduledef.function("lgamma", value="float")
def method_lgamma(self, space, value):
try:
res = rfloat.lgamma(value)
except (ValueError, OverflowError):
res = rfloat.INFINITY
gamma = space.float_w(space.send(self, space.newsymbol("gamma"), [space.newfloat(value)]))
sign = 1 if gamma >= 0 else -1 if gamma < 0 else 0
return space.newarray([space.newfloat(res), space.newint(sign)])

@moduledef.function("hypot", value1="float", value2="float")
def method_hypot(self, space, value1, value2):
return space.newfloat(math.hypot(value1, value2))

0 comments on commit 0ece2b8

Please sign in to comment.