## Mega Calc

A calculator that can process simple expressions, store variables, and perform basic trigonometry functions.

Commands: @create, @lock, @pemit, @set.
Features: regexp commands.
Compatibility: CobraMUSH, PennMUSH, RhostMUSH.

### Instructions

Copy and paste the below code into a compatible MUSH or MUX.

### MUSHCode for Mega Calc

@create Mega Calc
@lock Mega Calc==me
@set Mega Calc = !NO_COMMAND
&AUTHOR Mega Calc=Walker@M*U*S*H
&CALC Mega Calc=u(fun.calc,%0)
&CLEANPAREN Mega Calc=[setq(0,sub(words(%0,\(),1))][setq(1,sub(words(%0,\)),1))][if(gt(%q1,%q0),iter(lnum(sub(%q1,%q0)),\(,%b,))]%0[if(gt(%q0,%q1),iter(lnum(sub(%q0,%q1)),\),%b,))]
&CMD Mega Calc=
&CMD.CALC Mega Calc=\$^calc ([\^0-9a-zA-Z\-%\+\/\*\(\), \.]+)\$:think [set(me,result:[u(fun.calc,edit(%1,%b,))])][pemit(%#,Megacalc: [v(result)] %?)]
@set Mega Calc/CMD.CALC=regexp
&CMD.CALC_SHOW Mega Calc=\$calc:@pemit %#=[u(shortdesc)]
&CMD.MODE Mega Calc=\$^mode (rad|deg)\$:think u(fun.mode,%1)[pemit(%#,Mode is now %1)]
@set Mega Calc/CMD.MODE=regexp
&CMD.RCL Mega Calc=\$^rcl ([a-z])\$:think u(fun.rcl,%1)[pemit(%#,%1: [v(result)])]
@set Mega Calc/CMD.RCL=regexp
&CMD.ROLL Mega Calc=\$^roll ([\^0-9a-zA-Z\-%\+\/\*\(\), \.]+)\$:think [set(me,result:[u(fun.calc,edit(%1,%b,))])][emit(Megacalc: [v(result)])]
@set Mega Calc/CMD.ROLL=regexp
&CMD.STORE Mega Calc=\$^sto ([a-z])\$:think [set(me,var.%1:[v(result)])][pemit(%#,%1: [v(var.%1)])]
@set Mega Calc/CMD.STORE=regexp
&CMD.STORE_X Mega Calc=\$^sto ([a-z])=(.*)\$:think [set(me,var.%1:%2)][pemit(%#,%1: [v(var.%1)])]
@set Mega Calc/CMD.STORE_X=regexp
&CMD.TRIG Mega Calc=\$^(sin|cos|tan)\$:think set(me,result:[u(fun.trig,%1,[v(result)])])[pemit(%#,%1: [v(result)])]
@set Mega Calc/CMD.TRIG=regexp
&CONS.@ Mega Calc=v(result)
&CONS.ANS Mega Calc=v(result)
&CONS.E Mega Calc=e()
&CONS.PI Mega Calc=pi()
&CONS.RES Mega Calc=v(result)
&CONS.RESULT Mega Calc=v(result)
&DESCRIBE Mega Calc=A Mega Calculator%r%rThe display reads: [v(result)]%r%rMode is: [v(mode)]%r%rGlowing Neon Buttons:%r%b%b[ansi(h,calc <expression>)] - calculate an expression.%r%b%b[ansi(h,deg)] or [ansi(h,rad)] - change trig mode%r%b%b%b%b[ansi(h,sin)], [ansi(h,cos)], or [ansi(h,tan)] - get sin, cos, or tan of result.%r%b%b[ansi(h,sto <a-z>)] - store result into a variable%r%b%b[ansi(h,sto <a-z>=<function or number>)] - store an expression into a variable.%r%b%b[ansi(h,rcl <a-z>)] - put variable into result buffer%r%b%b[ansi(h,Constants: @ (result), PI, E)]
@set Mega Calc/DESCRIBE=no_command visual public nearby
&DROP Mega Calc=You drop the megacalc
@set Mega Calc/DROP=no_command
&FUN.CALC Mega Calc=setq(0,u(parse.negsub,u(parse.twoparens,u(parse.doubleneg,u(parse.vars,u(parse.varmuls,u(parse.result,edit(u(cleanparen,edit(%0,\,,)),%b,))))))))[iter(parens:\\\\\\\( power:\\\\\\\^ muldiv:/* addsub:~+,setq(0,u(rec.1,%q0,before(##,:),after(##,:))),%b,)]%q0
&FUN.CLEAR Mega Calc=set(me,result:%0)
&FUN.MODE Mega Calc=set(me,mode:%0)
&FUN.RCL Mega Calc=set(me,result:[v(var.%0)])
&FUN.STORE Mega Calc=set(me,var.%0:%1)
&FUN.TRIG Mega Calc=u(trig.[v(mode)].%0,%1)
&ODROP Mega Calc=drops the mega calculator
@set Mega Calc/ODROP=no_command
&PARSE.DOUBLENEG Mega Calc=edit(%0,--,+)
&PARSE.EXPRESSION Mega Calc=[setq(0,%0)][iter(modulo:\\\% power:^ muldiv:/* addsub:~+,setq(0,u(rec.1,%q0,before(##,:),after(##,:))),%b,)]%q0
&PARSE.MODULO Mega Calc=regedit(%0,\(\(\\\-|\)\[0-9\\\.\]*\)\(\\\%\)\(\[0-9\\\.\\\-\]*\),s(mod\(\$1,\$4\)))
&PARSE.MULDIV Mega Calc=regedit(%0,\(\(\\\-|\)\[0-9\\\.\]*\)\(\[\\\*\\\/\]\)\(\[\\\-0-9\\\.\]*\),s(switch\(\$3,/,fdiv\(\$1,\$4\),*,mul\(\$1,\$4\)\)))
&PARSE.MULDIV.OLD Mega Calc=regedit(%0,\(\(\\\-|\)\[0-9\\\.\]*\)\(\[\\\*\\\/\]\)\(\[\\\-0-9\\\.\]*\),s(switch\(\$3,/,fdiv\(\$1,\$4\),*,mul\(\$1,\$4\)\)))
&PARSE.NEGSUB Mega Calc=edit(regeditall(edit(%0,~,-),\(\^|\[^0-9\]\)\\\-\(\[0-9\\\.\\\(\\\)\]\),\$1NEGATIVE\$2),-,~,NEGATIVE,-)
&PARSE.PARENS Mega Calc=regedit(%0,\\\(\(\[0-9\\\+\\\~\\\-\\\^\\\*\\\/\\\.\]+\)\\\),u(parse.expression,\$1))
&PARSE.POWER Mega Calc=regedit(%0,\(\(\\\-|\)\[0-9\\\.\]*\)\(\\\^\)\(\[0-9\\\.\\\-\]*\),s(power\(\$1,\$4\)))
&PARSE.POWER.OLD Mega Calc=regedit(%0,\(\(\\\-|\)\[0-9\\\.\]+\)\(\\\^\)\(\[0-9\\\.\\\-\]+\),s(power\(\$1,\$4\)))
&PARSE.RESULT Mega Calc=regeditall(%0,(\[A-Z\]+),\([u(cons.\$1)]\),(\\d+)d(\\d+),die(\$1,\$2))
&PARSE.TRIG Mega Calc=regeditall(%0,\(\(SIN|COS|TAN|ABS\)\\\(
&PARSE.TWOPARENS Mega Calc=edit(%0,\)\(,\)*\(,\(\),\(0\))
&PARSE.VARMULS Mega Calc=regeditall(regeditall(regeditall(regeditall(%0,\\\)\(\[\\\.a-z0-9\]\),\)*\$1),\(\[a-z0-9\\\.\]\)\\\(,\$1*\(),\(\\\)|\[a-z\]|\[0-9\]\)\(\[a-z\]\),\$1*\$2),\(\[a-z\]\)\(\\\(|\[a-z\]|\[0-9\]\),\$1*\$2)
&PARSE.VARS Mega Calc=regeditall(%0,\(\[a-z\]\),s(if\(hasattrval\(me,var.\$1\),u\(fun.calc,v\(var.\$1\)\),0\)))
&REC.1 Mega Calc=if(regmatch(%0,\[%2\]),u(rec.2,u(parse.%1,%0),%1,%2),%0)
&REC.2 Mega Calc=if(regmatch(%0,\[%2\]),u(rec.2,u(parse.%1,%0),%1,%2),%0)
&RESULT Mega Calc=20
&SHORTDESC Mega Calc=A Mega Calculator%r%rThe display reads: [v(result)]
@set Mega Calc/SHORTDESC=no_command visual
&TRIG.DEG.COS Mega Calc=cos(fdiv(mul(%0,pi()),180))
&TRIG.DEG.SIN Mega Calc=sin(fdiv(mul(%0,pi()),180))
&TRIG.DEG.TAN Mega Calc=tan(fdiv(mul(%0,pi()),180))
&TYPE Mega Calc=tool
&VAR.A Mega Calc=4029
&VAR.B Mega Calc=4304
&VAR.C Mega Calc=1
&VAR.D Mega Calc=1
&VAR.I Mega Calc=1
&VAR.K Mega Calc=1024
&VAR.M Mega Calc=1024k
&VAR.N Mega Calc=20
&VAR.P Mega Calc=3.141593
&VAR.R Mega Calc=3
&VAR.S Mega Calc=30.9d
&VAR.W Mega Calc=x^2 + y^2
&VAR.X Mega Calc=3
&VAR.Y Mega Calc=PI * x ^ 2

look Mega Calc