SA-MP Forums Archive
[Include] matheval.inc - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] matheval.inc (/showthread.php?tid=658079)



matheval.inc - SyS - 22.08.2018

matheval

This is a simple library for evaluating mathematical expressions given as string literals.Currently supported operators are: If you have any issues or improvements to be made in this code just open an issue or pull request

Installation

If you are using sampctl just use

sampctl package install Sreyas-Sreelal/matheval

Otherwise just clone the repository

git clone https://www.github.com/sreyas-sreelal/matheval.git

and add matheval.inc to your pawno/includes folder

Usage

There is only one function

MathEval(expression[])

parameters
returns

For example :


Код:
#include<matheval>
main(){
    printf("(1+3)^(32/3)-1 = %f",MathEval("(1+3)^(32/3)-1"));
}
Testing

To run the tests:

sampctl package run

Dependencies
Repository
https://github.com/Sreyas-Sreelal/matheval


Re: matheval.inc - J0sh... - 22.08.2018

supports spaces thumbs up
good use of git too thumbs up


Re: matheval.inc - coool - 22.08.2018

Nice.


Re: matheval.inc - Hunud - 22.08.2018

Quote:
Originally Posted by Freshncool
Посмотреть сообщение
supports spaces thumbs up
good use of git too thumbs up
Thumbs down for dumbass.

OT: Good job.


Re: matheval.inc - SyS - 22.08.2018

Quote:
Originally Posted by ******
Посмотреть сообщение
Also, the tests don't actually do anything. They just confirm the answer is the same as itself, which will almost always be the case, they don't check that the answer is correct. So if your code evaluated "2+2" as 5, the test would pass, because "5==5"...
Yeah you are absolutely correct.I never did think of that.I will modify the test.
Quote:
Originally Posted by ******
Посмотреть сообщение
But nice use of a stack machine for evaluation. Though I think the final loop would be better just running until `evalTop==1`, then you return `evalStack[0]`, since if there is only one item left, it must be the result.
Edit: Ehh my method was actually scanning and pushing elements in OperandArray, into evalStack and if an operator is reached pop two elements from evalStack and operate and push the result into evalStack.So i think checking if there is one item left on evalstack will return the first element that is pushed and breaks the loop on first iteration.


Re: matheval.inc - Marshall32 - 24.08.2018

Quote:
Originally Posted by Freshncool
Посмотреть сообщение
supports spaces thumbs up
good use of git too thumbs up
This ^ and also really nice method to evaluate.+Rep


Re: matheval.inc - BigETI - 24.08.2018

mashallah brother


Re: matheval.inc - GhostHacker9 - 31.08.2018

Useful and also i can learn a lot about data structures from this.Thanks