Пример #1
0
def test_unary_minus_sin():
    """http://code.pediapress.com/wiki/ticket/450"""
    val = expr.expr("-sin(1.5707963267948966)")
    print val
    assert math.fabs(-1 - val) < 0.0001

    val = expr.expr("-sin ((90--82)*3.14159265358979/180)*(90+-80.0833333)*1.55*1.30522+49.3")
    print val
    assert math.fabs(46.507864831337 - val) < 0.0001
Пример #2
0
def test_unary_minus_sin():
    """http://code.pediapress.com/wiki/ticket/450"""
    val = expr.expr("-sin(1.5707963267948966)")
    print val
    assert math.fabs(-1 - val) < 0.0001

    val = expr.expr(
        "-sin ((90--82)*3.14159265358979/180)*(90+-80.0833333)*1.55*1.30522+49.3"
    )
    print val
    assert math.fabs(46.507864831337 - val) < 0.0001
Пример #3
0
    def EXPR(self, rl):
        import math

        if rl:
            try:
                ex = rl[0].strip()
                if not ex:
                    return u""
                val = expr.expr(ex)
                if int(val) == val and math.fabs(val) < 1e14:
                    return str(int(val))
                r = str(float(val))
            except Exception, err:
                # log("ERROR: error while evaluating #expr:%r\n" % (ex,))
                return self._error(err)

            if "e" in r:
                f, i = r.split("e")
                i = int(i)
                if i < 0:
                    sign = ""
                else:
                    sign = "+"
                fixed = str(float(f)) + "E" + sign + str(int(i))
                return fixed
            return r
Пример #4
0
    def EXPR(self, rl):
        import math
        if rl:
            try:
                ex = rl[0].strip()
                if not ex:
                    return u""
                val = expr.expr(ex)
                if int(val) == val and math.fabs(val) < 1e14:
                    return str(int(val))
                r = str(float(val))
            except Exception, err:
                # log("ERROR: error while evaluating #expr:%r\n" % (ex,))
                return self._error(err)

            if "e" in r:
                f, i = r.split("e")
                i = int(i)
                if i < 0:
                    sign = ''
                else:
                    sign = '+'
                fixed = str(float(f)) + "E" + sign + str(int(i))
                return fixed
            return r
Пример #5
0
 def IFEXPR(self, rl):
     try:
         ex = rl[0].strip()
         if ex:
             r = expr.expr(rl[0])
         else:
             r = False
     except Exception, err:
         # log("ERROR: error while evaluating #ifexpr:%r\n" % (rl[0],))
         return self._error(err)
Пример #6
0
 def IFEXPR(self, rl):
     try:
         ex = rl[0].strip()
         if ex:
             r = expr.expr(rl[0])
         else:
             r = False
     except Exception, err:
         # log("ERROR: error while evaluating #ifexpr:%r\n" % (rl[0],))
         return self._error(err)
Пример #7
0
    def EXPR(self, rl):
        if rl:
            try:
                r=str(expr.expr(rl[0]))
            except Exception, err:
                return self._error(err)

            if "e" in r:
                f,i = r.split("e")
                i=int(i)
                if i<0:
                    sign = ''
                else:
                    sign = '+'
                fixed=str(float(f))+"E"+sign+str(int(i))
                return fixed
            return r
Пример #8
0
    def EXPR(self, rl):
        if rl:
            try:
                r = str(expr.expr(rl[0]))
            except Exception, err:
                return self._error(err)

            if "e" in r:
                f, i = r.split("e")
                i = int(i)
                if i < 0:
                    sign = ''
                else:
                    sign = '+'
                fixed = str(float(f)) + "E" + sign + str(int(i))
                return fixed
            return r
Пример #9
0
#! /usr/bin/env python

import sys
import time
from mwlib import expr

e = []
for x in sys.stdin:
    e.append(eval(x))

print "have %s expressions" % len(e)
stime = time.time()
for x in e:
    expr.expr(u"1+2")
print "needed", time.time() - stime
Пример #10
0
 def IFEXPR(self, rl):
     try:
         r = expr.expr(rl[0])
     except Exception, err:
         return self._error(err)
Пример #11
0
 def IFEXPR(self, rl):
     try:
         r = expr.expr(rl[0])
     except Exception, err:
         return self._error(err)