Skip to content

Commit

Permalink
First stab at Math.lgamma
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Gaynor committed Apr 10, 2013
1 parent c9b9a2f commit 0ece2b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 0 additions & 7 deletions spec/tags/core/math/lgamma_tags.txt
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions topaz/modules/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 0ece2b8

Please sign in to comment.