Skip to content
The Xamarin.Forms RPN (Reverse Polish Notation) calculator running in WebAssembly
C# JavaScript
Branch: master
Clone or download
jeromelaban Merge pull request #13 from unoplatform/dependabot/nuget/Uno.UI-2.0.5…
…12-dev.3874

Bump Uno.UI from 2.0.512-dev.3522 to 2.0.512-dev.3874
Latest commit 18145d0 Nov 13, 2019

README.md

name description page_type languages products urlFragment
Xamarin.Forms - RPN Calculator
An RPN (Reverse Polish Notation) calculator allows numbers and operations to be entered without parentheses or an equal key. RPN (also called...
sample
csharp
xamarin
rpncalculator

RPN Calculator

An RPN (Reverse Polish Notation) calculator allows numbers and operations to be entered without parentheses or an equal key. RPN (also called postfix notation) is described in the Wikipedia article Reverse Polish notation and the RPN Calculator workbook, which shows an alternative approach to coding an RPN calculator for Xamarin.Forms.

RPN is based on a stack. Numbers are pushed on the stack by pressing the ENTER key. Unary operations (such as log and sin) pop a number from the stack, apply the operation, and push the result back on the stack. Binary operations (such as + and /) pop two numbers from the stack, perform the operation, and push the result on the stack.

To perform the calculation

5 × (3 + 4) – 2

press the following keys:

5 ENTER 3 ENTER 4 ENTER + × 2 ENTER –

The + operation adds 3 and 4, the times operation multiplies 5 and that result, and the minus operation subtracts 2 from that result.

The layout of the keys appears twice in the MainPage.xaml file, separately for portrait mode and landscape mode. The MainPage.xaml.cs code-behind file switches between these two layouts based on the relative width and height of the page.

The calculator logic is encapsulated in the RpnCalculatorViewModel.cs file. The XAML file and the ViewModel are linked through XAML-based data bindings, which are described in detail in the series of series of articles on Data Binding, and particularly the The Command Interface article.

RPN Calculator application screenshot

Author

Charles Petzold

You can’t perform that action at this time.