Shoutbox

Calulator Plugin - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Forum: Plug-Ins (/forumdisplay.php?fid=28)
+------ Thread: Calulator Plugin (/showthread.php?tid=31474)

Calulator Plugin by Orkblutt on 09-13-2004 at 10:55 PM

Yip,

here my first and really simple MsgPlus calculator plugin...


commands:

/xcalc algebric_expression

/xprecis floatting_point_precision  (by default precision = 2)


example:

/xcalc ((2+1)*(2+1))*(2+1)
=27

/xcalc (((2+1)*2+1)*2+1)
=15

/xcalc (666/77)*8+(2*3.5)-(2.78*8.7)
=52.01

/xprecis 16

/xcalc (666/77)*8+(2*3.5)-(2.78*8.7)
52.0088051948052050


CAUTION!
you must use () when some * or /

/xcalc 666/77*8
=1.08                             ==> FALSE !!!

/xcalc (666/77)*8          ==> TRUE !!!
=69.20

I'll correct that in futur releases and I'll implement all basic algebric function like abs(), mod(), pow(), sqrt(), ...

Futur versions will be multiple precision arithmetic (no bytes limitations ;))

Report all bugs here please.



RE: Calulator Plugin by RebelSean on 09-13-2004 at 11:23 PM

Just downloaded, installed. Works good. But I doubt if I will use it... No bugs. Works fine for me :d....Good Job (y)....


RE: Calulator Plugin by Orkblutt on 09-13-2004 at 11:25 PM

you're the first to test it ;)

I think I'll developp a complete math tool in the futur...
Don't know who will use it.. ehehe
just me? ihih


RE: Calulator Plugin by RebelSean on 09-13-2004 at 11:28 PM

I just use my calculator on my pc...:p...But I will give it to people if they ever ask for something like this....P.S. Why didn't you get beta testers before ya released?? :S


RE: Calulator Plugin by Orkblutt on 09-13-2004 at 11:33 PM

you're my beta tester ;)
Why are you asking that? Some bugs? :(


RE: Calulator Plugin by riahc4 on 09-13-2004 at 11:58 PM

You should make a installer. It looks pretty good from the looks of it tho. No bugs found.


RE: Calulator Plugin by Orkblutt on 09-13-2004 at 11:59 PM

I'll make an installer when it will be a little more advanced... it's just for test here :)


RE: Calulator Plugin by RebelSean on 09-14-2004 at 12:55 AM

No. No bugs. Just asking why didn't you get beta testers before you made it public :p.


RE: Calulator Plugin by Orkblutt on 09-14-2004 at 02:06 AM

because you are my beta testers... it's a plugin dev forum here I think... :)


RE: Calulator Plugin by RaceProUK on 09-14-2004 at 12:51 PM

Have you considered using Reverse Polish notation? It completely removes the need for parentheses.
Example:
(6+4)*10
becomes
6 4 + 10 *
Both result in 100.


RE: Calulator Plugin by Orkblutt on 09-14-2004 at 01:07 PM

Yes... but it's a less natural notation...
Implementation that use PostFix notation (RPN) are stack based... operands are popped from a stack, and calculation results are pushed back onto it. Although this concept may seem obscure at first, RPN has the advantage of being extremely easy for a computer to analyze due to it being a regular grammar.

I prefer to use Infix notation because it's easier to write the algebric expression. I'm not sure that everybody are familiar with Postfix ...


One classic exercise in computer science is to write a parser for algebraic expressions, that is, a program that takes an input string like


(3 + 5) * (-4 + (2 - 9))


and calculates the result of this expression. In fact, what you do to compute that expression is to convert it into an internal representation, and then evaluate that representation.

You can represent the expression given above by a linked list:
[Image: img003.gif]
where each node of the list either contains an operator or a number. Once the arithmetic expression is given in list form, evaluating it is easy and can be done in a straightforward, object oriented way...


RE: Calulator Plugin by jameslives on 09-14-2004 at 03:01 PM

The /xcalc is used by djmystics stuffplug so it is using stuffplug rather than yours


RE: Calulator Plugin by Orkblutt on 09-14-2004 at 03:03 PM

what's doing the /xcalc command from stuffplug?


RE: Calulator Plugin by jameslives on 09-14-2004 at 03:04 PM

your calculator plugin is using /xcalc


RE: Calulator Plugin by Orkblutt on 09-14-2004 at 03:06 PM

lol... thanks a lot!

and what's the action performed by the /xcalc comand from stuffplug ???


RE: Calulator Plugin by lhunath on 09-14-2004 at 03:07 PM

Postfix is rather complex and hard and weird for people who never used it before so I think you shouldn't convert your plugin to use that. Instead, you should figure out a way to effectivly convert infix to postfix, and then interprete the postfix. That way you won't have any problems with the ()'s etc.


RE: Calulator Plugin by jameslives on 09-14-2004 at 03:08 PM

stuffplug uses /xcal as a calculator too but it is less technical


RE: Calulator Plugin by Orkblutt on 09-14-2004 at 03:15 PM

quote:
Postfix is rather complex and hard and weird for people who never used it before so I think you shouldn't convert your plugin to use that. Instead, you should figure out a way to effectivly convert infix to postfix, and then interprete the postfix. That way you won't have any problems with the ()'s etc.


I'm ok.

quote:
stuffplug uses /xcal as a calculator too but it is less technical


lol... less technical?? :|
Hummm... 1+1=3 in stuffplug? ;)
I'll try to make an advanced calculator (some algebrical fct, and no byte limitation)... so maybe stuffplug can remove /xcalc command from her release... or I can change that in next versions.

That will be a good idea that we can see a page with all commands from all popular plugins.



RE: Calulator Plugin by jameslives on 09-14-2004 at 03:23 PM

Make an advanced calc that wil b cool(ish)!


RE: Calulator Plugin by RaceProUK on 09-14-2004 at 04:08 PM

quote:
Originally posted by lhunath
Postfix is rather complex and hard and weird for people who never used it before
It's not really complex tbh, but I agree it's counter-intuitive for those used to infix.
RE: Calulator Plugin by lhunath on 09-14-2004 at 04:10 PM

Looks complex ;)


RE: Calulator Plugin by RaceProUK on 09-14-2004 at 04:12 PM

( 6 + 4 ) * 10 has 7 important tokens.
6 4 + 10 * has five important tokens.
Taking into account the stack-implentation of RPN, it is slightly simpler, especially from a program's POV.
* RaceProUK may use Reverse Polish for any maths questions on his next exam...


RE: Calulator Plugin by aNILEator on 09-14-2004 at 04:26 PM

i don't see whats wrong with createing a quick text /calc
to be a /run link to the MS calculator


RE: Calulator Plugin by CookieRevised on 09-14-2004 at 05:15 PM

quote:
Originally posted by Orkblutt
/xcalc 666/77*8
=1.08                             ==> FALSE !!!

/xcalc (666/77)*8          ==> TRUE !!!
=69.20
That makes me wonder how you do the calculation and what method you use... because first of all in many language of today there is already an evaluation function for such things (dunno about C++ though). If you use that, you only need to pass the string and you would never have problems like that....

If you do seperate the numbers yourself then, again, this is some basic flaw in your algorithm, as it would be very easy to do such things in a home-made function:

* use a recursive function
* get the deepest linked parenthesis
* calculate the result of that:
  "*" and "/" coming first, then "+" and "-"
  Also calculate from LEFT to RIGHT!!! <== the error you made ( * or / doesn't take precedence over each other, just like + and - doesnt....)
    1) 666 / 77
    2) 8.64 * 8
  not:
    1) 77 * 8
    2) 666 / 616

* update the "string"
* exit the function and go up 1 level

This is a realy realy basic way in doing it (without optimazations), and you would never have a problem with parenthesis...

note about using "-": it is best that you don't implement substractions, but only additions! If a minus is used, it should be considered part of the number, not a math-function. If you do this you also wont have problems with: "8 - 5" because your function would calculate "8 + -5", but most importantly, you can do "8 * -5" without any additional coding...


So... I'm realy interested in the method you use...

PS:
http://www.codeproject.com/cpp/FastMathParser.asp
http://www.codeproject.com/cpp/RPNcalculator.asp
http://www.programmersheaven.com/zone3/cat415/30915.htm
http://www.informit.com/articles/article.asp?p=21484
http://trubetskoy1.narod.ru/english/ppne.html <= implement this and you also have a PPN calculator...
RE: Calulator Plugin by Orkblutt on 09-14-2004 at 05:55 PM

quote:
That makes me wonder how you do the calculation and what functions you use... because in most language of today (VB, C++, etc... ) there is already an evaluation function for such things. If you use that, you only need to pass the string and you would never have problems like that....


C++, VB do that ?

quote:
note about using "-": it is best that you don't implement substractions, but only additions! If a minus is used, it should be considered part of the number, not a math-function. If you do this you also wont have problems with: "8 - 5" because your function would calculate "8 + -5", but most importantly, you can do "8 * -5" without any additional coding...

have you test mine ? :)

quote:
So... I'm realy interested in the method you use...


humm it's a little bit complex to explain (I'm too bad in english!!)

Using a little more advanced parser tree method  than http://www.informit.com/articles/article.asp?p=21484 but it's the same principle...
RE: Calulator Plugin by MessEnGer on 09-14-2004 at 06:21 PM

Hey nice plugin works great

P.S. srry for the earlier confusion


RE: Calulator Plugin by Millenium_edition on 09-14-2004 at 06:35 PM

you don't need to register it.


RE: Calulator Plugin by RaceProUK on 09-14-2004 at 07:29 PM

quote:
Originally posted by CookieRevised
http://trubetskoy1.narod.ru/english/ppne.html
This is probably the best of the links, as it describes an algorithm for converting infix to RPN, which you can then evaluate. That way, users can use the familiar infix, and you can implement the simpler RPN calculator.
RE: Calulator Plugin by Orkblutt on 09-14-2004 at 09:58 PM

thank you!
I'll see if it's necessary to use RPN (if I've too more difficulties with Infix)
thanks for this link