Coder Social home page Coder Social logo

xeintdm / go-calculator Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 7 KB

A command-line calculator application written in Go, capable of performing a variety of mathematical operations, including basic arithmetic, exponentiation, and trigonometric functions.

License: The Unlicense

Go 100.00%
advanced-calculator calculator calculator-application go golang

go-calculator's Introduction

Go Calculator

Welcome to the Go Calculator! This is a command-line calculator application written in Go, capable of performing a variety of mathematical operations, including basic arithmetic, exponentiation, and trigonometric functions.

Features

  • Supports basic arithmetic operations: addition (+), subtraction (-), multiplication (*), division (/), and exponentiation (^).
  • Handles nested and multiple operations with parentheses.
  • Includes trigonometric functions: sin(x), cos(x), tan(x).
  • Provides square root function: sqrt(x).
  • User-friendly interface with prompt for user input.
  • Exits cleanly with the exit command.

Getting Started

Prerequisites

  • Go (1.16 or higher)

Installation

  1. Clone the repository:
git clone https://github.com/XeinTDM/Go-Calculator.git
cd go-calculator
  1. Run the executable:
go build -o calculator.exe calc.go
  1. (Optional) Compress the executable with UPX for smaller size:
upx --best calculator.exe

Usage

  1. Run the calculator:
./calculator
  1. Enter your calculations when prompted.
  • Example calculations:
Enter calculation: 3 + 5 * (2 - 4)
Result: -7.000000
Enter calculation: sin(3.14 / 2)
Result: 1.000000
  1. Exit the calculator: Type exit and press Enter to quit the program.

How It Works

The calculator reads input from the user, processes the input to convert it into a format that can be evaluated, and then computes the result. It uses the Shunting Yard algorithm to handle operator precedence and associativity, converting infix expressions to postfix notation for easier evaluation.

Key Components

  • Tokenizer: Splits the input string into meaningful tokens (numbers, operators, functions).
  • Shunting Yard Algorithm: Converts infix expressions to postfix notation.
  • Postfix Evaluator: Computes the result from the postfix expression.
  • Error Handling: Manages various errors such as invalid operators, mismatched parentheses, and division by zero.

go-calculator's People

Contributors

xeintdm 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.