Raevnos's Calculator

A four function (Well, 5 if you count the ^ (Power) key,) calculator with working () keys, and an LCD display.

Author: Raevnos
Category: Other
Commands: @create, @link, @lset, @pemit, @set.
Compatibility: CobraMUSH, PennMUSH.

Instructions

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

MUSHCode for Raevnos's Calculator

@create Calculator
@link Calculator = #1580
@lock/Basic Calculator==#1622
@lset Calculator/Basic=no_inherit
@set Calculator = LINK_OK
@set Calculator = VISUAL
@set Calculator = NO_COMMAND
&ADD Calculator=if(strlen(%1), add(u(parse_sub, %0), u(parse_sub, %1)), u(parse_sub, %0))
&CALC Calculator=u(parse_parens, trim(edit(ulocal(insert_mul, edit(%0, %b, , --, +)), \(, %b\(, \), \)%b)))
&CALC_CMD Calculator=$calc *:@pemit %#=Calc> [u(calc, %0)]
&DESCRIBE Calculator=A four function (Well, 5 if you count the ^ (Power) key,) calculator with working () keys (Thanks to Trispis for the idea for how to do that bit, as well as lots of bug testing), and an LCD display. To use, just 'calc <expression>' where <expression> is something like 1+2-3
@set Calculator/DESCRIBE=no_command visual public nearby
&DIV Calculator=if(strlen(%1), fdiv(u(parse_exp, %0), u(parse_exp, %1)), u(parse_exp, %0))
&EXP Calculator=if(strlen(%1), power(u(parse_fact, %0), u(parse_fact, %1)), u(parse_fact, %0))
&INSERT_MUL Calculator=if(regmatch(%0, lit(([0-9\)])(\()|(\))([0-9\(])), 0 1 2 3 4), u(insert_mul, edit(%0, %q0, if(%q1, %q1, %q3)*[if(%q2, %q2, %q4)])), %0)
&LICENSE Calculator=All code on this object (Raevnos's Calculator) is released under the Library Gnu Public License. A copy of that license is avaliable at [tagwrap(a, href="http://www.gnu.org/copyleft/lgpl.html", http://www.gnu.org/copyleft/lgpl.html)]
&MUL Calculator=if(strlen(%1), mul(u(parse_div, %0), u(parse_div, %1)), u(parse_div, %0))
&PARSE_ADD Calculator=fold(add, rest(%0, +), first(%0, +), +)
&PARSE_DIV Calculator=fold(div, rest(%0, /), first(%0, /), /)
&PARSE_EXP Calculator=fold(exp, rest(%0, ^), first(%0, ^), ^)
&PARSE_FACT Calculator=switch(right(%0, 1), !, u(%xc/factorial, edit(%0, !, )), %0)
&PARSE_MUL Calculator=fold(mul, rest(%0, *), first(%0, *), *)
&PARSE_PARENS Calculator=if(pos(\(,%0), u(parse_parens, trim(edit(replace(%0, match(%0, \(*\)), u(parse_add, edit(grab(%0, \(*\)), \(, , \), ))), %b, , \(, %b\(, \), \)%b))), u(parse_add, %0))
&PARSE_SUB Calculator=if(regmatch(%0, \[\*/\]-), u(parse_mul, %0), fold(sub, rest(%0, -), first(%0, -), -))
&SUB Calculator=if(strlen(%1), if(%0, sub(u(parse_mul, %0), u(parse_mul, %1)), u(parse_mul, -%1)), u(parse_mul, %0))
&XA Calculator=#244
&XB Calculator=#245
&XC Calculator=#247
&XE Calculator=#260