Code Monkey home page Code Monkey logo

polishcalculator's Introduction

PolishCalculator

A command-line polish-style calculator for ncurses compatible operating systems

Works on an "operator first" basis, so 1 + 2 is written as +1 2

Supports most operators

Can store numbers as either long doubles, or as fraction; it will convert from fraction to floating point as needed

Usage:

>PolishCalculator <expression>

Will just calculate the following expression, it already has the variables p (pi) and e (e) set to approximate values

>PolishCalculator

Will open up a calculator command line where you can just directly type in the expressions to calculate; it also supports setting custom varibles, unlike the single expression version

Valid operators:

Single Operand:

Convert to decimal: d - Converts the operand to a floating point type form a fraciton if it is not already one. 1/3 -> 0.33..

Negative: _ - negates the operand(this means that negative numbers are written as _x not -x). 23 -> -23

Square Root: r - will attempt to keep it in exact fraction form, many convert to decimal in unsuccesssful

Sine: s

Consine: c

Tangent: t

Inverse Sine: S

Inverse Consine: C

Inverse Tangent: T

Double Operand:

Union: u - combines two numbers into a set of those numbers. u2 3 -> {2, 3}

Add: +

Subtract: -

Multiply: *

Divide: /

Modulo: % - programming style modulo

Power: ^

Log: l

Assignment Equals: = - only valid in the beginning of an input in the calculate command-line version(the second usage). (e.g. =a +2 3 will set the variable a to 5 so then *a 2 would yield 10, but =+2 3 a would not be valid, the variable must come first) Variable will remember if they are fractions, decimals, or even sets

Sets

A single "number"(or variable) can actually exist as a set of numbers, and they can be used in normal mathematical expression as you'd expect. For example: +u1 2u3 4 = {4, 5, 6} (written in normals maths as {1, 2} + {3, 4} = {4, 5, 6}). As you can see, it will find the sum of every number in the first set with every number in the second set, removng any repeats. It does discriminate based on the fractionness of the number. (i.e. 4.0 and 4 will not combine into a single number because one is a floating point and the other is considered a fraction)

Decimal(Floating Point) Vs Fractions

whenever you type in a number, even in the form x.x (e.g. 12.2) it will convert it to the fractional equivalent (61/5). The only way it converts to a decimal is explicitly(with the decimal operator) or automatically(trying to find the square root of 2).

Why?

Because of the fact that polish notation is completely unambiguous, there is no need for parenthesis. Also because having a simple, yet powerful, calculator on the command line ready at any time is very useful

polishcalculator's People

Contributors

danielbatterystapler avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.