diff --git a/astparser.py b/astparser.py
index c97055c..a202944 100644
a
|
b
|
class RuntimeError(ParserError): |
107 | 107 | msg += ": %s" % (self._msg) |
108 | 108 | return msg |
109 | 109 | |
| 110 | class ArguementError(ParserError): |
| 111 | """Class for error during executing.""" |
| 112 | |
| 113 | def __init__(self, msg, start, eqn, end=None): |
| 114 | ParserError.__init__(self, msg, start, end) |
| 115 | |
| 116 | def __str__(self): |
| 117 | msg='' |
| 118 | msg += ": %s" % (self._msg) |
| 119 | return msg |
| 120 | |
110 | 121 | class Helper: |
111 | 122 | |
112 | 123 | def __init__(self, parent): |
… |
… |
class AstParser: |
462 | 473 | return ret |
463 | 474 | except Exception, e: |
464 | 475 | msg = str(e) |
465 | | raise RuntimeError(msg, ofs) |
| 476 | raise ArguementError(msg, ofs, 0) |
| 477 | |
466 | 478 | |
467 | 479 | elif isinstance(node, ast.Num): |
468 | 480 | if type(node.n) == types.FloatType: |
diff --git a/calculate.py b/calculate.py
index 7ee58a4..3cdbd2f 100644
a
|
b
|
from sugar.graphics.xocolor import XoColor |
42 | 42 | from shareable_activity import ShareableActivity |
43 | 43 | from layout import CalcLayout |
44 | 44 | from mathlib import MathLib |
45 | | from astparser import AstParser, ParserError, RuntimeError |
| 45 | from astparser import AstParser, ParserError, RuntimeError, ArguementError |
46 | 46 | from svgimage import SVGImage |
47 | 47 | |
48 | 48 | from decimal import Decimal |
diff --git a/functions.py b/functions.py
index 8a737ff..b5efe99 100644
a
|
b
|
abs.__doc__ = _( |
112 | 112 | 'abs(x), return absolute value of x, which means -x for x < 0') |
113 | 113 | |
114 | 114 | def acos(x): |
115 | | return _inv_scale_angle(math.acos(x)) |
| 115 | if x>1 or x<-1: |
| 116 | raise ValueError(_('acos(x) only defined for x E [-1,1]')) |
| 117 | else: |
| 118 | return _inv_scale_angle(math.acos(x)) |
116 | 119 | acos.__doc__ = _( |
117 | 120 | 'acos(x), return the arc cosine of x. This is the angle for which the cosine \ |
118 | 121 | is x. Defined for -1 <= x < 1') |
… |
… |
def add(x, y): |
136 | 139 | add.__doc__ = _('add(x, y), return x + y') |
137 | 140 | |
138 | 141 | def asin(x): |
| 142 | if x>1 or x<-1: |
| 143 | raise ValueError(_('asin(x) only defined for x E [-1,1]')) |
139 | 144 | return _inv_scale_angle(math.asin(x)) |
140 | 145 | asin.__doc__ = _( |
141 | 146 | 'asin(x), return the arc sine of x. This is the angle for which the sine is x. \ |
… |
… |
def exp(x): |
227 | 232 | exp.__doc__ = _('exp(x), return the natural exponent of x. Given by e^x') |
228 | 233 | |
229 | 234 | def factorial(n): |
| 235 | if n<0: |
| 236 | raise ValueError(_('Factorial(x) is only defined for integers x>=0')) |
| 237 | |
230 | 238 | if type(n) not in (types.IntType, types.LongType): |
231 | | raise ValueError(_('Factorial only defined for integers')) |
| 239 | raise ValueError(_('Factorial(x) is only defined for integers x>=0')) |
232 | 240 | |
233 | 241 | if n == 0: |
234 | 242 | return 1 |
… |
… |
def floor(x): |
283 | 291 | floor.__doc__ = _('floor(x), return the largest integer smaller than x.') |
284 | 292 | |
285 | 293 | def inv(x): |
286 | | return 1 / x |
| 294 | if x==0: |
| 295 | raise ValueError(_('Can not divide by zero')) |
| 296 | return div(1, x) |
287 | 297 | inv.__doc__ = _('inv(x), return the inverse of x, which is 1 / x') |
288 | 298 | |
289 | 299 | def is_int(n): |
… |
… |
is_int.__doc__ = ('is_int(n), determine whether n is an integer.') |
304 | 314 | |
305 | 315 | def ln(x): |
306 | 316 | if float(x) > 0: |
307 | | return math.log(float(x)) |
| 317 | return div(math.log(float(x)),math.log(math.e)) |
308 | 318 | else: |
309 | 319 | raise ValueError(_('Logarithm(x) only defined for x > 0')) |
310 | 320 | ln.__doc__ = _( |