Hello There!
Alternative to Agrahams ExpressionEvaluator Library,
I have just recently converted my evaluator code from B4p to B4a as my start coding for Android.
Function sample use: answer=evaluate.MATHTEXT(txtinp1.Text)
Currently supports the following:
Operators in precedence order are
! : factorial (170 maximum)
^ : exponent
* / mod : multiply, divide and modulus,
+ - : add and subtract
Functions supported are:
COS(r), SIN(r), TAN(r), ACOS(n), ASIN(n), ATAN(n) : radians
COSD(d), SIND(d), TAND(d), ACOSD(n), ASIND(n), ATAND(n) : degrees
LN(n)base e, LOG(n)base 10,
SQRT(n), INT(n),& ABS(n)
Constants recognised are
CPI : Pi
CE : Ex
Also supports Eng'g numbers input like "1.255E-12", "1.255E+12", or "1.255E12"
The code can be easily updated:
Constant values can be added in a lists at line 25
Functions like 'Cos(n)' can be added at line 111 and line 460 (just follow the pattern.)
Customize error messages by searching 'Calcresult' variable.
May not be perfected yet. You can have a look and test for bugs.
Trying and sharing your additions and improvements on this code will be greatly appreciated. Thanks.
EDIT: File updated. Negative result value not returning now fixed.
Alternative to Agrahams ExpressionEvaluator Library,
I have just recently converted my evaluator code from B4p to B4a as my start coding for Android.
Function sample use: answer=evaluate.MATHTEXT(txtinp1.Text)
Currently supports the following:
Operators in precedence order are
! : factorial (170 maximum)
^ : exponent
* / mod : multiply, divide and modulus,
+ - : add and subtract
Functions supported are:
COS(r), SIN(r), TAN(r), ACOS(n), ASIN(n), ATAN(n) : radians
COSD(d), SIND(d), TAND(d), ACOSD(n), ASIND(n), ATAND(n) : degrees
LN(n)base e, LOG(n)base 10,
SQRT(n), INT(n),& ABS(n)
Constants recognised are
CPI : Pi
CE : Ex
Also supports Eng'g numbers input like "1.255E-12", "1.255E+12", or "1.255E12"
The code can be easily updated:
Constant values can be added in a lists at line 25
Functions like 'Cos(n)' can be added at line 111 and line 460 (just follow the pattern.)
Customize error messages by searching 'Calcresult' variable.
May not be perfected yet. You can have a look and test for bugs.
Trying and sharing your additions and improvements on this code will be greatly appreciated. Thanks.
EDIT: File updated. Negative result value not returning now fixed.
Attachments
Last edited: