Giter Club home page Giter Club logo

scientific-calculator's Introduction

Scientific Calculator

Overview:

This is a simple calculator program designed to mimic the functionality of a basic scientific calculator, inspired by the TI-30 calculator. While it doesn't encompass all the features of a TI-30, it aims to replicate the input behavior, where clicking buttons generates a string of inputs on the screen, as opposed to a simpler calculator that only displays one input on the screen at once.

Logic:

The calculator follows the order of operations, known as PEMDAS (Parentheses, Exponents, Multiplication and Division, Addition and Subtraction), to ensure accurate calculations.

  • Parentheses: Operations inside parentheses are performed first.
  • Exponents1: Exponentiation is evaluated from right to left.
  • Multiplication and Division: Multiplication and division operations are evaluated from left to right.
  • Addition and Subtraction: Addition and subtraction operations are evaluated from left to right.

Under the Hood:

To process the input and perform calculations, the calculator utilizes two main algorithms:

  1. Infix to Postfix Conversion:

    • The input expression, provided in infix notation, is converted to postfix notation using a stack-based algorithm. This conversion ensures the correct order of operations during evaluation.
  2. Postfix Evaluation:

    • The postfix expression is evaluated using another stack-based algorithm. The calculator iterates through each element of the postfix expression, performs the appropriate operation (such as addition, subtraction, multiplication, division, or exponentiation), and updates the stack until the final result is obtained.

How to Use:

Use the calculator here.

  1. Enter the numbers and operators by clicking the corresponding buttons on the calculator interface.
  2. The input will be displayed as a string on the screen, reflecting the sequence of buttons pressed.
  3. Press the "=" button to calculate the result.
  4. The result will be displayed on the screen.

Please note that this calculator supports basic scientific calculations following the PEMDAS rule. However, due to the simplicity of the implementation, it may not handle complex scientific functions or advanced mathematical operations. It's important to review the input and ensure it adheres to the expected format and constraints to obtain accurate results from the calculator.

Remember to input your expressions carefully, adhering to the rules of PEMDAS, to obtain accurate results.

Footnotes

  1. Exponentiation is evaluated from right to left to align with the convention used in many programming languages. For example, in the expression "2^3^2," the exponentiation operation is performed as "2^(3^2)" rather than "(2^3)^2." โ†ฉ

scientific-calculator's People

Contributors

jordanccox avatar

Watchers

 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.