DescriptionJust a simple calculator. It still has a few bugs. like, 144^144 outputs infinity, large numbers don't quite work, and a few others. Please notify me if you find any more.InstructionsUse the d-pad to move the cursor.
Use the touch screen to type stuff.
7 Comment(s)12Me21Head AdminSyntax HighlighterReceived for creating the code syntax highlighter on SBSNight PersonI like the quiet night and sleep late.Express YourselfIt would probably be a good idea not to parse the - as part of numbers, since it's actually an operator (for example, -1^2 is actually -(1^2)).
You'll have to distinguish between negation and subtraction though (maybe use ~ for negation internally)NathanielAmazing ContributorSomeone thinks I'm an awesome person who has done so much for the community!AchievementsScholarReceived for knowing a great deal about programming topicsAchievementsFinal(?) Contest WinnerI won the (possibly) final SmileBASIC Source Contest! October 2018Programming ContestYeah... The system isn't perfect. I'll try to fix it eventually.niconiiVideo GamesI like to play video games!HobbiesExpert ProgrammerProgramming no longer gives me any trouble. Come to me for help, if you like!Programming StrengthDrawingI like to draw!HobbiesWell, this is a nice calculator, but... this isn't RPN (aka postfix), it's infix. Maybe you saw someone on Miiverse mention the shunting-yard algorithm, but that is for infix, not RPN.
RPN is a different way of writing math, it's not the usual syntax we normally use.
Infix: 1 * 2 + 3 / (4 - 5)
RPN: 1 2 * 3 4 5 - / +
PN: + * 1 2 / 3 - 4 5
Note that RPN and PN don't require parentheses at all, nor an order of operations. In addition, RPN in particular is very simple to parse and evaluate. You can simply read it left to right, using a stack:
Push 1 onto stack (1)
Push 2 onto stack (1, 2)
Multiply top two items on stack (2)
Push 3 onto stack (2, 3)
Push 4 onto stack (2, 3, 4)
Push 5 onto stack (2, 3, 4, 5)
Subtract top two items on stack (2, 3, -1)
Divide top two items on stack (2, -3)
Add top two items on stack (-1)
And -1 is indeed the correct result.
P.S. If this seems interesting to you, there are actually programming languages which use RPN for their entire syntax, with functions called like 1 2 3 FUNC and so on. Forth is a very notable example.NathanielAmazing ContributorSomeone thinks I'm an awesome person who has done so much for the community!AchievementsScholarReceived for knowing a great deal about programming topicsAchievementsFinal(?) Contest WinnerI won the (possibly) final SmileBASIC Source Contest! October 2018Programming ContestI know what RPN is. This calculator converts infix to RPN before it solves it. Also, what is a decent way of checking to see if the equation can be converted to RPN? As in-
"1+/1" to "1,1,+,/" 'doesn't work
"1+-1" to "1+(-1)" to "1,-1,+" 'works
"(5)(7)" to "(5)*(7)" to "5,7,*" 'works
"-(10+2)" to "-1*(10+2)" to "-1,10,2,+,*" 'works
'etc.niconiiVideo GamesI like to play video games!HobbiesExpert ProgrammerProgramming no longer gives me any trouble. Come to me for help, if you like!Programming StrengthDrawingI like to draw!HobbiesWell, "RPN calculator" tends to specifically mean "a calculator that you type RPN into". Several calculators exist which use only RPN, the calculator in macOS has an RPN mode, and so on. It's kind of a misleading name if you can't actually type RPN into it.
If you're asking how to check if RPN is valid after you already have "1,1,+,/", simply start with a counter at 0, and for each item, if it's a number, add 1, and if it's an operator, subtract 1. This counter represents the number of items on the stack.
If the counter is less than 1, you have too many operators. If it's greater than 1, you have too many numbers.NathanielAmazing ContributorSomeone thinks I'm an awesome person who has done so much for the community!AchievementsScholarReceived for knowing a great deal about programming topicsAchievementsFinal(?) Contest WinnerI won the (possibly) final SmileBASIC Source Contest! October 2018Programming ContestAh, I see. Thanks!NathanielAmazing ContributorSomeone thinks I'm an awesome person who has done so much for the community!AchievementsScholarReceived for knowing a great deal about programming topicsAchievementsFinal(?) Contest WinnerI won the (possibly) final SmileBASIC Source Contest! October 2018Programming Contestdefinitely didn't add any easter eggs...
Infix: 1 * 2 + 3 / (4 - 5) RPN: 1 2 * 3 4 5 - / + PN: + * 1 2 / 3 - 4 5
Note that RPN and PN don't require parentheses at all, nor an order of operations. In addition, RPN in particular is very simple to parse and evaluate. You can simply read it left to right, using a stack: And -1 is indeed the correct result. P.S. If this seems interesting to you, there are actually programming languages which use RPN for their entire syntax, with functions called like"1+/1" to "1,1,+,/" 'doesn't work "1+-1" to "1+(-1)" to "1,-1,+" 'works "(5)(7)" to "(5)*(7)" to "5,7,*" 'works "-(10+2)" to "-1*(10+2)" to "-1,10,2,+,*" 'works 'etc.
definitely didn't add any easter eggs...