Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Expression evaluator
#11
AGAMEMNUS:

I think you should try to get your method to work. It's the only solution so far that I think is going to work. Nobody is going to implement and test about 700 lines of code to do it the conventional way. That's too much work. Your approach is a shortcut, but can be done. The result is as correct and precise as QB can be.
*****
Reply
#12
Hmmm, in relation to this "expression evaluator": StatLib is forcing me to teach the computer to add, subtract all over again... it's a pity Nexinarus didn't suggest a "make a function that adds two strings"... Tongue
Reply
#13
ORACLE,
In Stalib, you mention having to "teach" it to subtract. What subtract method did you use?
1) the method where if the digit you're subtracting is greater than the one above, you borrow 1 from the top of the next digit position and add 10 to your top digit.
2) the method where if the digit your subtracting is greater than the one above, you add 1 to the bottom of the next digit position, and add 10 to your top digit.

Method 1 is very hard to program because when you go to "borrow" you may have to move over several digit positions to find one that is not zero.

Method 2 is very easy to program.
*****
Reply
#14
Quote:Nobody is going to implement and test about 700 lines of code to do it the conventional way. That's too much work.

Of course it is. That's why I implemented this simple evaluator which takes numeric literals and *, /, + and - operations in just 30 lines:

Code:
This was somewhat wrong

EDIT: Check a later post for OK code Smile
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#15
Quote:ORACLE,
In Stalib, you mention having to "teach" it to subtract. What subtract method did you use?
1) the method where if the digit you're subtracting is greater than the one above, you borrow 1 from the top of the next digit position and add 10 to your top digit.
2) the method where if the digit your subtracting is greater than the one above, you add 1 to the bottom of the next digit position, and add 10 to your top digit.

Method 1 is very hard to program because when you go to "borrow" you may have to move over several digit positions to find one that is not zero.

Method 2 is very easy to program.
*****

Ahem... I'm adding and subtracting using STRINGS. Each number is stored in a string so numbers in QBasic can be 32,767 digits long. For addition etc I have to extract each individual number and add/subtract them, and then carry. The base routines are actually by Neo for his BIGINT lib (I was gonna use agamemnus's clone but it doesn't work properly), but now I am adding decimal, negative and standard form support (the *hard* part).
Reply
#16
ORACLE,
I figured you were adding/subtracting strings.
You didn't answer my question of what method you're using to subtract. Is it that you're using Neo's routines and you don't really care?
*****
Reply
#17
Yeah, only the addition works 100% right..

Perhaps the multiplication. Bleh. Evil evil evil.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#18
1) the method where if the digit you're subtracting is greater than the one above, you borrow 1 from the top of the next digit position and add 10 to your top digit.
2) the method where if the digit your subtracting is greater than the one above, you add 1 to the bottom of the next digit position, and add 10 to your top digit.
-----------------------------------------------------------------------------------
AGAMEMNUS,

Try subtracting 123 from 9999. If this works, try subtracting 999 from 10000. If this in turn doesn't work, then the subtract routine is using method #1 above. Implementing method #1 is not easy, actually it's a mess.

Most Americans who have to implement subtraction will use method #1 because that's what they were taught in school, sad to say. My mother was from Europe, and before I went to school she taught me the method #2 of subtracting. So, when I first implemented a subtract routine, it was easy.
*****
Reply
#19
^_^'

Anybody seen/tested my idea?
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#20
Nathan,
I think Nexinarus should test and comment on your submitted routine. He's the author of this challenge.
*****
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)