Skip to content

kantic/termc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

termc

Introduction and Goals

termc is a calculator for the command line. The goal of this project is to provide an easy-to-use and intuitive command line calculator with a basic range of functions. It supports the basic operations ("+", "-", "*", "/", "%" and "^") as well as the following built-in mathematical functions:

  • cos
  • sin
  • tan
  • cot
  • acos
  • asin
  • atan
  • acot
  • cosh
  • sinh
  • tanh
  • coth
  • acosh
  • asinh
  • atanh
  • acoth
  • ln
  • exp
  • sqrt
  • pow (e.g. "pow(5, 2)" = 25)
  • root (e.g. "root(4, 2)" = 2)
  • im
  • re

Futhermore, the following built-in constants are supported:

  • e
  • pi
  • i (the imaginary unit)

Specialities

Complex numbers

termc supports complex numbers. Example:

$ termc
>>> sin(5+3i)
ans = -9.654125476854839+2.841692295606352i

Scientific notation

termc supports scientific notation. Example:

$ termc
>>> 25E-3
ans = 0.025

Non-Decimal input and output

termc supports input and output in decimal, binary, octal and hexadecimal system. Furthermore, termc supports output in the IEEE754 binary format. Example:

$ termc
>>> 0b101.11
ans = 5.75

>>> format hex

>>> ans
ans = 0x5.c

>>> 0o753.457
ans = 0x1eb.978

>>> format ieee754

>>> ans
ans = 0b100000001111110101110010111100000000000000000000000000000000000

>>> format dec

>>> ans
ans = 491.591796875

User-defined constants

termc supports the definition of custom constants. Example:

$ termc
>>> custom_constant = 5*pi/4

>>> cos(custom_constant)
ans = -0.7071067811865477

User-defined functions

termc supports the definition of custom functions. Example:

$ termc
>>> f(a, b, c) = a + b - c

>>> f(5, 3-2i, sin(pi/2))
ans = 7-2i

Serialization and Deserialization to / from JSON

termc supports the serialization and deserialization of all custom functions and constants. Therefore, all definitions can be saved to a file. Example:

$ termc
>>> f(x) = x^2

>>> c = 79.882

>>> save /home/kantic/termc_context.json

>>> exit

$ termc
>>> load /home/kantic/termc_context.json

>>> f(c)
ans = 6381.133924000001

>>> ...

Command History

termc remembers the user inputs in a session. Thus, the user is able to quickly get previous inputs by using the up and down arrow-keys.

Guiding error messages

termc prints helpful error messages if the user made some mistakes in his input. Example:

$ termc
>>> pow(2.7, 3
Error: Expected symbol ")".
pow(2.7, 3
          ^~~~

>>> cis(pi)
Error: Expected function or operation.
cis(pi)
  ^~~~ Found: cis

MultiOS

termc compilation has been tested on both linux (Debian 8) and Windows (Windows 10). All unix-like operating systems on which rust is available should work, too!

Modes of Operation

termc supports two different modes of operation.

Call mode

In this mode, the user can pass mathematical expressions as command line arguments to termc.

$ termc 1+2 5*7 "cos(pi)"
3;35;-1

Interactive mode

For this mode, no additional command line arguments are passed to the call of termc. It will then start in interactive mode.

$ termc
>>> 1+2
ans = 3

>>> 5*7
ans = 35
...

License

GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 A copy of the license can be found in the root directory of this repository.

About

A command line calculator.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages