Skip to content
Permalink
Browse files

Merge pull request #618 from gemoe100/adding_methods_to_Math

Adding methods to math
  • Loading branch information
alex committed Apr 15, 2013
2 parents cb0e65c + 7bb84ab commit f48cfb5b3cc124d58964fea40a26c4ae7cd4e01d
@@ -15,6 +15,7 @@ Authors
* Konstantin Makarchev
* Curt Micol
* Bill Mill
* Gerd Mömken
* Charles Oliver Nutter
* Thomas Pelletier
* Greg Price
@@ -1,7 +1 @@
fails:Math.erf returns a float
fails:Math.erf returns the error function of the argument
fails:Math.erf raises a TypeError if the argument cannot be coerced with Float()
fails:Math.erf returns NaN given NaN
fails:Math.erf raises a TypeError if the argument is nil
fails:Math.erf accepts any argument that can be coerced with Float()
fails:Math#erf is accessible as a private instance method
@@ -1,7 +1 @@
fails:Math.erfc returns a float
fails:Math.erfc returns the complimentary error function of the argument
fails:Math.erfc raises a TypeError if the argument cannot be coerced with Float()
fails:Math.erfc returns NaN given NaN
fails:Math.erfc raises a TypeError if the argument is nil
fails:Math.erfc accepts any argument that can be coerced with Float()
fails:Math#erfc is accessible as a private instance method

This file was deleted.

@@ -108,6 +108,23 @@ def test_gamma(self, space):
w_res = space.execute("return Math.gamma(Float::NAN)")
assert math.isnan(space.float_w(w_res))

def test_lgamma(self, space):
res_w = space.execute("return Math.lgamma(6.0)")
w_res1, w_res2 = space.listview(res_w)
self.assert_float_equal(space.float_w(w_res1), math.log(120))
assert space.int_w(w_res2) == 1

res_w = space.execute("return Math.lgamma(-1)")
w_inf = space.execute("return Float::INFINITY")
w_res1, w_res2 = space.listview(res_w)
assert self.unwrap(space, w_res1) == self.unwrap(space, w_inf)
assert space.int_w(w_res2) == 1

res_w = space.execute("return Math.lgamma(Float::NAN)")
w_res1, w_res2 = space.listview(res_w)
assert math.isnan(self.unwrap(space, w_res1))
assert space.int_w(w_res2) == 1

def test_hypot(self, space):
w_res = space.execute("return Math.hypot(3, 4)")
assert self.unwrap(space, w_res) == 5
@@ -186,3 +203,11 @@ def test_tan(self, space):
def test_tanh(self, space):
w_res = space.execute("return [Math.tanh(0), Math.tanh(1), Math.tanh(1234)]")
assert self.unwrap(space, w_res) == [0, math.tanh(1), 1.0]

def test_erf(self, space):
w_res = space.execute("return [Math.erf(0), Math.erf(10), Math.erf(-10)]")
assert self.unwrap(space, w_res) == [0.0, 1.0, -1.0]

def test_erfc(self, space):
w_res = space.execute("return [Math.erfc(-1), Math.erfc(0), Math.erfc(1.5)]")
assert self.unwrap(space, w_res) == [math.erfc(-1), 1.0, math.erfc(1.5)]
@@ -107,7 +107,9 @@ def method_lgamma(self, space, value):
res = rfloat.lgamma(value)
except (ValueError, OverflowError):
res = rfloat.INFINITY
gamma = space.float_w(space.send(self, space.newsymbol("gamma"), [space.newfloat(value)]))
gamma = (1 if value == -1 or math.isnan(value) else
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)])

@@ -187,6 +189,14 @@ def method_tan(self, space, value):
def method_tanh(self, space, value):
return space.newfloat(math.tanh(value))

@moduledef.function("erf", value="float")
def method_erf(self, space, value):
return space.newfloat(rfloat.erf(value))

@moduledef.function("erfc", value="float")
def method_erfc(self, space, value):
return space.newfloat(rfloat.erfc(value))


class W_DomainError(W_StandardError):
classdef = ClassDef("Math::DomainError", W_StandardError.classdef, filepath=__file__)

0 comments on commit f48cfb5

Please sign in to comment.
You can’t perform that action at this time.