Author Topic: Expression Evaluator 3  (Read 3567 times)

0 Members and 1 Guest are viewing this topic.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Expression Evaluator 3
« on: March 13, 2008, 04:48:25 pm »
Script Name: Expression Evaluator 3
Script Description: Evaluates an expression Example: Evaluate('7+4*3') returns '19'. This is for scripters, not server owners. If you wish to use this script in your script, feel free to, but please note my name.
Original Author: DorkeyDear (Curt)
Core Version: 2.6.3
Required Files:
filename (minimal version) link
convert.pas (5) http://curt.soldatrs.com/boosters/convert.pas
math.pas (20) http://curt.soldatrs.com/boosters/math.pas
strops.pas (3) http://curt.soldatrs.com/boosters/strops.pas
expreval.pas (1.23) http://curt.soldatrs.com/boosters/expreval.pas

Notes:
Case-sensitive
Ignores spaces
Prompting a boolean, anything non-0 is true
Returning a boolean, 1=true, 0=false
"~" is the negative character

Operators:
PI: float; value of pi
E: float; value of e
PHI: float; value of Phi (do "1 - PHI" to get the value of phi)
abs float: float; absolute value
sign float: integer; sign (-1 for negatives, 0 for 0, 1 for positives)
int float: integer; integer part of value
float float: float; float part of value
float roundto integer: float; rounds to nearest specified decimal place
round float: integer; rounds to the nearest integer
floor float: integer; floors the number
ceil float: integer; ceilings the number
sqrt float: float; square-root
sin float: float; sine
cos float: float; cosine
tan float: float; tangent
sec float: float; secant
csc float: float; cosecant
cot float: float; cotangent
arcsin float: float; arc-sine
arccos float: float; arc-cosine
arctan float: float; arc-tangent
arcsec float: float; arc-secant
arccsc float: float; arc-cosecant
arccot float: float; arc-cotangent
ln float: float; natural logarithm (slow and inaccurate)
not boolean: boolean; not
integer !: integer; factorial
integer c integer: integer; combination
integer p integer: integer; permutation
float ^ integer: float; exponents
float * float: float; multiplication
float / float: float; division
float % float: float; modulus
float + float: float; addition
float - float: float; subtraction
integer << integer: integer; bit shift left
integer >> integer: integer; bit shift right
float < float: boolean; less than
float <= float: boolean; less than or equal to
float > float: boolean; greater than
float >= float: boolean; greater than or equal to
float == float: boolean; equal to
float != float: boolean; not equal to
boolean and boolean: boolean; logical and
boolean xor boolean: boolean; logical xor
boolean or boolean: boolean; logical or

Order of Precedence:
1 () left to right
2 PI E PHI left to right
3 abs sign int roundto round floor ceil sqrt arcsin, arccos, arctan, arcsec, arccsc, arccot, sin, cos, tan, sec, csc, cot right to left
4 not right to left
5 ! left to right
6 c p left to right
7 ^ left to right
8 * / % left to right
9 + - left to right
10 << >> left to right
11 < <= > >= left to right
12 == != left to right
13 and left to right
14 xor left to right
15 or left to right

Older Versions:
1: http://nopaste.org/p/a1PijA3tkb
2: http://nopaste.org/p/aTx9wvzeh

Please report any bugs or suggestions
« Last Edit: July 02, 2008, 06:03:42 pm by DorkeyDear »

Offline BombSki

  • Flagrunner
  • ****
  • Posts: 927
    • Climbing-soldiers.net
Re: Expression Evaluator
« Reply #1 on: March 14, 2008, 09:34:41 am »
nice.. thats quite an advanced script there :o good work

Offline rhide

  • Major
  • *
  • Posts: 60
  • Coffee-addict
    • Vrastar-Hai soldat clan
Re: Expression Evaluator
« Reply #2 on: March 15, 2008, 05:39:40 pm »
I'm impressed! Good job!
Warning! Division by zero seriously injures yourself and the people in your surroundings.

Proud member of Vrastar-Hai:
http://www.guldheden.com/~erga050/vrastar-hai

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: Expression Evaluator
« Reply #3 on: March 17, 2008, 05:57:13 am »
oh man, this is even more useful than my prime number finder

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Expression Evaluator
« Reply #4 on: March 17, 2008, 04:06:10 pm »
oh man, this is even more useful than my prime number finder
reminds me of my calculator program i made that finds prime factors of a given number :P man i hate how slow calculators are.

Offline sai`ke

  • Camper
  • ***
  • Posts: 318
  • Can't be arsed to remove christmas avatar
Re: Expression Evaluator
« Reply #5 on: March 17, 2008, 04:21:23 pm »
Neat stuff! Creative way of using the script core.
#soldat.ttw #ttw.gather --- Quakenet!
http://ttwforums.com

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Expression Evaluator 3
« Reply #6 on: June 29, 2008, 05:54:28 pm »
So it has finally been remade, with working negatives and longer than one character long operators in a single release!

EDIT:
For those who want to add your own operators, feel free to; with the way its setup, it shouldn't be extremely difficult.

Date Posted: June 17, 2008, 01:47:36 pm
Update:
  • added roundto operator
  • added 12 trigonometric operators
  • added c and p operators (aka nCr, nPr)
  • added not operator
  • modified ! operator to be factorial
    Now requires Math Operations 18

    Could anybody help me figure out a way to do log functions? Changing the base will be simple once I get some sort of function.

    Date Posted: June 29, 2008, 06:24:18 pm
    Update:
  • added support for constants (PI, E, PHI are built in)

Note that built-in constants will be capital for a reason. Its easiest to describe with an example:
Say we have the constant "ë", and want to use the operator "sec"... so we have the string "sec2", the e in there will be replaced with the constant value, so we will have "s2.71828182845905c2" and then the c operator will try to work with the constant e which is not what we want.

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Expression Evaluator 3
« Reply #7 on: June 29, 2008, 06:36:44 pm »
heh I see you got the arc stuff working.
nice job, I will be using this in a script I'm working on.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Expression Evaluator 3
« Reply #8 on: June 29, 2008, 07:50:35 pm »
Update:
  • added float operator
  • added ln operator (inaccurate and slow)
    Now requires Math Operations 20