include("import") func ToNumber(x) fvar(res) res = x if (typeof(x) == 2) res = "float("&&x&&")" end return(res) end func BuildExp(_data) fvar(s,o1,o2) o1 = ToNumber(Op1) o2 = ToNumber(Op2) switch(OpType) case '+': return(o1 && ' ' && OpType && ' ' && o2) case '-': return(o1 && ' ' && OpType && ' ' && o2) case '*': return(o1 && ' ' && OpType && ' ' && o2) case '/': return(o1 && ' ' && OpType && ' ' && o2) case 'and': return(o1 && ' & ' && o2) case 'or': return(o1 && ' | ' && o2) case 'xor': return(o1 && ' ^ ' && o2) case 'not': return('~' && o1) case 'div': return(o1 && ' // ' && o2 case 'mod': fvar(t,u) t = o1 u = o2 if ((typeof(t) = 7) or (typeof(u) = 7)) need_math() return('math.fmod(' && t && ', ' && u && ')') else return('(' && t && ') % (' && u && ')') end case 'shl': return (o1 && '<<' && o2) case 'shr': return (o1 && '>>' && o2) case 'x^y': need_math() return ('math.pow(' && o1 && ', ' && o2 && ')') case 'cos': need_math() return ('math.cos(' && isdef(AngleMode)?o1:('math.radians('&&o1&&')') && ')') case 'sin': need_math() return ('math.sin(' && isdef(AngleMode)?o1:('math.radians('&&o1&&')') && ')') case 'tan': need_math() return ('math.tan(' && isdef(AngleMode)?o1:('math.radians('&&o1&&')') && ')') case 'acos': need_math() s = 'math.acos(' && o1 && ')' if (isndef(AngleMode)) s = 'math.angle(' && s && ')' end return s case 'asin': need_math() s = 'math.asin(' && o1 && ')' if (isndef(AngleMode)) s = 'math.angle(' && s && ')' end return s case 'atan': need_math() s = 'math.atan(' && o1 && ')' if (isndef(AngleMode)) s = 'math.angle(' && s && ')' end return s case 'atan2': need_math() s = 'math.atan2(' && o1 && ', ' && o2 && ')' if (isndef(AngleMode)) s = 'math.angle(' && s && ')' end return s case 'ch': need_math() return ('math.cosh(' && isdef(AngleMode)?o1:('math.radians('&&o1&&')') && ')') case 'sh': need_math() return ('math.sinh(' && isdef(AngleMode)?o1:('math.radians('&&o1&&')') && ')') case 'th': need_math() return ('math.tanh(' && isdef(AngleMode)?o1:('math.radians('&&o1&&')') && ')') case 'ach': need_math() s = 'math.acosh(' && o1 && ')' if (isndef(AngleMode)) s = 'math.angle(' && s && ')' end return s case 'ash': need_math() s = 'math.asinh(' && o1 && ')' if (isndef(AngleMode)) s = 'math.angle(' && s && ')' end return s case 'ath': need_math() s = 'math.atanh(' && o1 && ')' if (isndef(AngleMode)) s = 'math.angle(' && s && ')' end return s case 'log': need_math() return 'math.log(' && o1 && ', ' && o2 ')' case 'lg': need_math() return 'math.log10(' && o1 && ')' case 'ln': need_math() return 'math.log(' && o1 && ')' case 'exp': need_math() return 'math.exp(' && o1 && ')' case 'sqr': need_math() return 'math.pow(' && o1 && ', 2)' case 'sqrt': need_math() return 'math.sqrt(' && o1 && ')' case 'abs': return 'abs(' && o1 && ')' case 'sign': return '(' && o1 && '/abs(' && o1 && '))' case 'round': return 'round(' && o1 && ')' case 'frac': need_math() return '(math.modf(' && o1 && ')[0])') case 'trun': need_math() return 'math.trunc(' && o1 && ')') case 'min': return 'min(' && o1 && ', ' && o2 && ')' case 'max': return 'max(' && o1 && ', ' && o2 && ')' end end func doOperation(_data) fvar(s) s = code(BuildExp(_data)) if(linked(Result)) println(res, ' = ', s) event(onResult, res) else event(onResult, s) end end func doClear print(res, ' = ', Default) end func Result(_data) if(linked(doOperation) or linked(doClear)) return(res) else return(BuildExp(_data)) end end