1. Pypy
  2. Untitled project
  3. lang-smalltalk

Commits

Lars Wassermann  committed ee08c90

added guards for float-primitives to return NaN and Infinity, according to Smalltalk requirements when the math module raises the according errors

  • Participants
  • Parent commits 5b79cdc
  • Branches default

Comments (0)

Files changed (1)

File spyvm/primitives.py

View file
  • Ignore whitespace
 
 @expose_primitive(FLOAT_SIN, unwrap_spec=[float])
 def func(interp, s_frame, f):
-    w_res = interp.space.wrap_float(math.sin(f))
-    return w_res
+    try:
+        return interp.space.wrap_float(math.sin(f))
+    except ValueError:
+        return interp.space.wrap_float(rfloat.NAN)
 
 @expose_primitive(FLOAT_ARCTAN, unwrap_spec=[float])
 def func(interp, s_frame, f):
 
 @expose_primitive(FLOAT_EXP, unwrap_spec=[float])
 def func(interp, s_frame, f):
-    w_res = interp.space.wrap_float(math.exp(f))
-    return w_res
+    try:
+        return interp.space.wrap_float(math.exp(f))
+    except OverflowError:
+        return interp.space.wrap_float(rfloat.INFINITY)
 
 MAKE_POINT = 18