Page 1 of 1

Metalogic Calculator 3.3 now based on wxWidgets!

Posted: Sun Nov 20, 2005 10:57 pm
by metalogic
Hi all,
My freeware expression calculator http://www.metalogicsw.com/calculator/ has been ported to wxWidgets.

Please keep in mind that this is just an old very simple project that I wrote way back in college and is definitely not a reflection of my best work. :oops: Still, it does give you the result in dec/hex/oct/bin so developers may find it useful.

I want to put an image on my page "powered by wxWidgets" or something along those lines. I think I've seen that somewhere but can't find it. Just want to promote wxWidgets (and encourage everyone else to do so).

Enjoy!

Posted: Sun Nov 20, 2005 11:07 pm
by leio
The community link on www.wxwidgets.org has the icon, and asks to spread the word with that image.

Posted: Mon Nov 21, 2005 7:19 am
by metalogic
Thanks leio.

Posted: Mon Nov 21, 2005 10:21 am
by Jorg
Looks very nice :-)
What do you use for formula parsing?

- Jorgen

Posted: Mon Nov 21, 2005 7:29 pm
by metalogic
Jorg wrote:Looks very nice :-)
Thanks!
Jorg wrote:What do you use for formula parsing?
I wrote the parser myself. :idea:

Posted: Mon Nov 21, 2005 8:29 pm
by Jorg
Cool .. :-) a parser freak like me .. hehe
- Jorgen

Posted: Mon Nov 21, 2005 11:20 pm
by metalogic
:D

Posted: Tue Nov 22, 2005 2:42 am
by lowjoel
i do direct substitution for my parser :roll: expression goes in, recurse the thing and solve it bit by bit... and the result is substituted to the source expression...

Posted: Tue Nov 22, 2005 4:47 am
by metalogic
Yes, I do the same thing. Parse the expression string into a token list. Then as I solve each set of operands, I substitute them for one result token and so on.
Great minds think alike :)

The hardest thing is to figure out the operator precedence, especially when you throw parenthesis in the mix.

Posted: Tue Nov 22, 2005 6:46 am
by lowjoel
my RDP works like this:

Variable add/remove? If yes -> handle vars
No -> Add/Subtract
Add/Subtract calls multiply/div before evauluating
multiply/div calls powers before evaulating
powers call functions (sin, tan, acos etc) before evulating
functions call brackets before evaulating
brackets call variable substitution before evaulation
variable substitution call parser intuition before evaulation
then it works its way out...

brackets are a nice case, they just make another parser instance with the expression inside the brackets, and it goes on... and on.... until the deepest bracket is evulated. so my parser obeys the rules of operations lol, (), then ^, then */ and finally +-, i figured that functions come before powers... so yea... and when there are operators of equal precedence the parser will go LTR... like humans would :P

Posted: Tue Nov 22, 2005 7:18 am
by metalogic
Yes, about the same here except that I never got around to adding support for functions into my parser. I guess it wouldn't be a huge addition but I really don't maintain this project much anymore. In fact, I hadn't touched it in over a year until I decided to port it to Visual C++/wxWidgets (from Borland C++ Builder/VCL).

So, since you seem to have done a lot of the same work, I have a question for you. One of my biggest struggles was decimal floating point. When doing calculators or financial applications, binary floating point (float, double) is not accurate enough. I struggled to find a free decimal floating point library for C++ but couldn't. So I had to resort to some ugly hack.

How did you solve this? Or did you stick to binary floating point?

For anyone unfamiliar with the problems of binary floating point, here's some info:
http://www2.hursley.ibm.com/decimal/dec ... ml#inexact

Posted: Tue Nov 22, 2005 8:44 am
by lowjoel
i use apfloat for the thing, i added a preferences panel entry for parser precision, which defaults to 32 sugnificant figures. I wrote all the math functions (ok, most of it) myself...

Posted: Tue Nov 22, 2005 8:45 am
by lowjoel
and of course, if you wanted to have that error minimised pass /Op to VC for better floating pt precision...

Posted: Tue Nov 22, 2005 5:57 pm
by metalogic
Thanks for the info lowjoel. I will take a look at apfloat when I have some time.

For the time being though, what I'm using works quite nicely. I use the Variant/Decimal data type. That is a 128 bit decimal floating point which is perfect for my purposes.

My only problem with it is that it ties my otherwise mostly cross platform project to Windows. That's why I'd like a better solution.

I did make sure to encapsulate the implementation of my decimal data type so that if I were to swap out data types, my program wouldn't have to change (other than the "wrapper" of course).

Of course, since I'm in no hurry to change this, I might just wait until the decimal128 data type is added to standard C++
http://www.open-std.org/jtc1/sc22/wg21/ ... n1839.html

Posted: Tue Nov 22, 2005 11:53 pm
by lowjoel
lol, std C++ has some issues to solve.. lol