Giter VIP home page Giter VIP logo

calculatrs's Introduction

calculatrs

A python-like calculator for simple math on the terminal. It only supports a handful of basic operators; if you need more, just use actual python. If you only need to do simple arithmetic, though, this should be fine.

Currently:

  • All integers are 128-bit signed

  • All floating-point values are 64-bit IEEE754.

  • Integers are coerced to floats in mixed expressions.

  • Values can be explicitly cast to a type: int(2.0) or float(2). For integers, this truncates the value.

  • Integers support the following basic operations:

    • +, -, *, /: basic arithmetic. Note that we use integer division for integer-typed operands.
    • <<, >>: left and right shift
    • b ** e: b raised to the power e. If e is a float, b is cast to a float also. If e is an integer, e is cast to a 32-bit unsigned integer.
  • Floats support the following basic operations:

    • +, -, *, /: basic arithmetic. Note that we use floating-point division for float-typed operands.
    • b ** e: b raised to the power e. e may be a float or an integer, but if it is an integer, it will be truncated to 32-bits.
  • Precedence aims to be sane, though I haven't tested thoroughly:

    +, - Lower Precedence
    All others Higher Precence
  • All operators are right-associative.

  • Expressions can be grouped with ( <expr> ), as one would expect.

  • The special _ value represents the previous (typed) result, which is stored in /tmp/calculatrs. It can be used any place a value is expected. If an error occurs, no change is made to the saved value.

  • In order to make it easier to use directly in the terminal, the following alternate syntaxes exist:

    • * == x
    • ** == ^^

Building

You will need stable Rust.

cargo build

Installing

You can install from cargo:

cargo install calculatrs

The installed binary is called c.

Usage

Suppose you install the binary on your path

> c 10 / 5
2
> c '10 / 5'
2

Beware of your shell expanding * into "list all files".

calculatrs's People

Stargazers

 avatar  avatar

Watchers

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