Skip to content
Permalink
Browse files

correctly handle some error conditions

  • Loading branch information
Alex Gaynor
Alex Gaynor committed Apr 10, 2013
1 parent 422e17d commit c9b9a2f4d912c1f5330c770022863433ebeef95d
Showing with 4 additions and 5 deletions.
  1. +4 −5 topaz/modules/math.py
@@ -6,7 +6,6 @@

from topaz.module import Module, ModuleDef, ClassDef
from topaz.objects.exceptionobject import W_StandardError, new_exception_allocate
from rpython.rlib.rfloat import NAN


class Math(Module):
@@ -120,7 +119,7 @@ def method_log(self, space, value, base=math.e):
res = math.log(value) / math.log(base)
except ValueError:
if value == 0.0:
res = float("-inf")
res = float(-rfloat.INFINITY)
else:
raise space.error(space.getclassfor(W_DomainError), 'Numerical argument is out of domain - "log"')

@@ -132,7 +131,7 @@ def method_log10(self, space, value):
res = math.log10(value)
except ValueError:
if value == 0.0:
res = float("-inf")
res = float(-rfloat.INFINITY)
else:
raise space.error(space.getclassfor(W_DomainError), 'Numerical argument is out of domain - "log10"')

@@ -144,7 +143,7 @@ def method_log2(self, space, value):
res = math.log(value) / math.log(2)
except ValueError:
if value == 0.0:
res = float("-inf")
res = float(-rfloat.INFINITY)
else:
raise space.error(space.getclassfor(W_DomainError), 'Numerical argument is out of domain - "log2"')

@@ -171,7 +170,7 @@ def method_tan(self, space, value):
try:
res = math.tan(value)
except ValueError:
res = NAN
res = rfloat.NAN
return space.newfloat(res)

@moduledef.function("tanh", value="float")

0 comments on commit c9b9a2f

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