Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Program Announcements / Simple maths parser (designed for scripts)

Author
Message
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 29th Oct 2006 21:17
Here is a maths parser that I wrote:



It is designed for use in a scripting system, and although it does not use BIDMAS (or BODMAS) you can still use brackets.
One thing is, that when you call it with your equation in a string, you must add an extra ) at the end, so that it knows to return.

It recognises these symbols: + - * / ^ ( )

It will return a real number.

The function you must call is:
equation(equat$)

equat$ is a string containing the equation to calculate.

If you find any bugs, plz tell me as I will be using it in my latest game.

Mr Kohlenstoff
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Germany
Posted: 30th Oct 2006 17:22
Uh, great!
I've programmed a similar function some months ago, but I think it wasn't as fast and didn't support brackets.

Here just a small example for those who want to see the result quickly.



Good work Diggsey.

Visit the DBPro - Speed up your game-Thread. http://forum.thegamecreators.com/?m=forum_view&t=88661&b=1
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 30th Oct 2006 17:41 Edited at: 30th Oct 2006 17:58
Thanks! Finally a reply (after over 20 views!)

But in that code, you didn't put in the extra bracket at the end

Quote: "
when you call it with your equation in a string, you must add an extra ) at the end, so that it knows to return
"


edit:
one other thing, negative numbers must be enclosed in brackets.

Login to post a reply

Server time is: 2024-05-26 16:49:03
Your offset time is: 2024-05-26 16:49:03