Skip to content
/ clc Public

Command Line Calculator written in Rust ๐Ÿฆ€

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

ymgyt/clc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿงฎ clc - Command Line Calculator

clc on crates.io Documentation (latest release) Changelog License License

Clc is a Command line calculator written in Rust ๐Ÿฆ€ It eval given expression and print result.


๐Ÿ“– Table of Contents (Toc)

๐Ÿ’ป Installation
๐Ÿ‘ฉโ€๐Ÿ’ป Usage
๐Ÿฆ€ Using Clc in Rust Codes
๐Ÿ•ธ Access clc via GraphQL
๐Ÿชช License

๐Ÿ’ป Installation

There are prebuilt x86-64 binaries for Linux, macOS and Windows on the release page.
You can install the latest release from source using cargo, or build directly from a source checkout.

๐Ÿ“ฆ Via cargo

cargo install clc

๐Ÿง Linux

curl -sSLf https://github.com/ymgyt/calculator/releases/download/0.1.4/clc-x86_64-unknown-linux-gnu.tar.gz | tar zxf - -C /usr/local/bin

๐ŸŽ Mac

curl -sSLf https://github.com/ymgyt/calculator/releases/download/0.1.4/clc-x86_64-apple-darwin.tar.gz | tar zxf - -C /usr/local/bin

๐Ÿณ Docker

To use clc with docker, execute the following command.

docker run --rm -it ghcr.io/ymgyt/clc:latest

๐Ÿ‘ฉโ€๐Ÿ’ป Usage

Execute the clc command to start a repl session. type the expression to evaluate and press Enter.
To exit the session, type quit or press Ctrl + C.

$ clc
Version: v0.1.4
To quit, press Ctrl+C or type quit
โฏ sqrt(sqrt(16)) * (100 - 1) * (100 + 1) / 9
2222
โฏ quit
bye

You can also retrieve results directly without using a repl session. pass the expression to evaluate with --eval flag

clc --eval 'sqrt(-2^2) - abs(2)'

๐Ÿƒ Lambda expression

Some functions take lambda expression as argument. A lambda expression is written like |x| { x^2 }.
{,} are optional, so the above expression can also be written as follows |x| x^2.

โฏ sig(1,10 |x| x^2)
385

โฏ sig(1,10 |x| sig(1,10 |y| x*y))
3025

๐Ÿด Supported Functions

identifier description
sqrt(n) Returns the square root of a number
Return NaN if a negative number provided
pow(n,m) Raise n to the power of m. (= n ^ m)
abs(n) Compute the absolute value of n
sig(n,m,lambda) Execute lambda with values from n to m and return the sum of the results

๐Ÿฅฃ Constants

identifier description
pi Archimedesโ€™ constant (ฯ€)
e Eulerโ€™s number (e)

๐Ÿฆ€ Using Clc in Rust

Clc is also available in Rust codes with clc-engine

use clc_engine::Calculator;

fn main() {
    let clc = Calculator::new();
    let eval = clc.calculate_line("sqrt(sqrt(16)) * (4 + 2)");

    assert_eq!(eval, Ok(12.));
}

๐Ÿ•ธ Access clc via GraphQL

clc-gqlexposes clc with graphql api.
To run clc-gql with docker ,execute the following command.

docker run --rm --publish 9696:9696 ghcr.io/ymgyt/clc-gql:latest

then access

curl \
  -X POST \
  -d '{"query": "{ eval(expression: \"100 - 1\") }"}' \
  http://localhost:9696/graphql

{"data":{"eval":99.0}}

playground can be accessed from localhost:9696/graphsql/playground.

๐Ÿชช License

This project is available under the terms of either the Apache 2.0 license or the MIT license.

About

Command Line Calculator written in Rust ๐Ÿฆ€

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages