Version of the ec engineering calculator suitable for older versions of python
Python Other
Failed to load latest commit information.


ec: An Engineering Calculator

This calculator is noteworthy in that it employs a stack model of computation (Reverse Polish Notation), it supports numbers with SI scale factors and units, and uses a text-only user interface.

Requires Python version 2.3 or later. Be aware that some features are not available with the earlier versions of Python.

More information on both ec and ec0 can be found at NurdleTech .

To get the source code:

$ git clone git://

Once cloned, you can get the latest updates using:

$ git pull

Alternatively, you can download a zip file from:

If you go this route, you will have to unzip the file using the unzip command.

To run the regression tests:

$ ./test

To install:

$ ./install

This installs ec in ~/.local. Be sure to add ~/.local/bin to your PATH. With early versions of python, you my see an ImportError when invoking ec. If this is happens, you should add the site-packages directory onto your python path using:

$ export PYTHONPATH=$HOME/.local/lib/python-<vers>/site-packages

if you use bash as your shell, or:

> setenv PYTHONPATH ~/.local/lib/python-<vers>/site-packages

if you use csh.

To read the EC manual:

$ man ec

On earlier versions of Linux you might need to supplement your man path using:

$ export MANPATH=$HOME/.local/man:$MANPATH

To run EC:

$ ec

What follows is a brief tour of EC:

To perform operations in EC, you first enter the numbers, then the operators. In particular, as you enter the numbers they are pushed onto the stack. The operators then take numbers from the stack and replace them with the result. The operations are performed immediately and there is no use of parentheses to group calculations. Any intermediate results are stored on the stack until needed.

To add two numbers:

0: 4 5 +

The prompt displays the value of the x-register.

You can string together an arbitrarily long calculation on a single line:

0: 4 5 + 6 7 + *

Or, you can string a long calculation over multiple lines (this calculates the value of two parallel 100 ohm resistors):

0: 100
100: 100
100: ||

Select operators can be entered without preceding them with a space if they follow a number or a name. For example:

0: 4 5* 6 5+ *

To store a value into a variable, type an equal sign followed by a name. To recall it, simply use the name:

0: 100MHz =freq
100MHz: 2pi* =omega
628.32M: 1pF =Cin
1pF: 1 omega/ Cin/

Display variables using:

628.32M: vars
  Cin = 1pF
  Rref = 50 Ohms
  freq = 100MHz
  omega = 628.32M

Rref is a special variable that is set by default to 50 Ohms, but you can change its value. It is used in dBm calculations.

EC supports units, but in a relatively conservative way. You can enter them and it remembers them, but they do not survive any operation other than a copy. In this way it should never display incorrect or misleading units, however it displays units when it can. For example:

0: 100MHz =freq
100 MHz: 2pi* "rads/s" =omega
628.32 Mrads/s: vars
  Rref = 50 Ohms
  freq = 100 MHz
  omega = 628.32 Mrads/s
628.32 Mrads/s: 2pi /

Notice that EC captured units on 100MHz and stored them into the memory freq. Also notice that the units of "rads/s" were explicitly specified, and they were also captured. Finally, notice that dividing by 2pi cleared the units.

Normally units are given after the number, however a dollar sign would be given immediately before:

0: $100M

You can enter hexadecimal, octal, or binary numbers, in either traditional programmers notation or in Verilog notation. For example:

0: 0xFF
255: 0o77
63: 0b1111
15: 'hFF
255: 'o77
63: 'b1111

You can also display numbers in hexadecimal, octal, or binary in both traditional or Verilog notation. To do so, use hex, oct, bin, vhex, voct, or vbin:

0: 255
255: hex4
0x00ff: vbin

You can convert voltages into dBm using:

0: 10 vdbm

You can convert dBm into voltage using:

0: -10 dbmv
100 mV:

Both of these assume a load resistance that is contained in memory Rref, which by default is 50 Ohms.

At start up EC reads and executes commands from files. It first tries '~/.ecrc' and runs any commands it contains if it exists. It then tries './.ecrc' if it exists. Finally it runs any files given on the command line. It is common to put your generic preferences in '~/.exrc'. For example, if your are a physicist with a desire for high precision results, you might use:

h 2pi / 'J-s' =hbar

This tells EC to use 6 digits of resolution and predefines hbar as a constant. The local start up file ('./.ecrc') or the file given as a command line argument is generally used to give more project specific initializations. For example, in a directory where you are working on a PLL design you might have an './.ecrc' file with the following contents:

88.3uSiemens =kdet
9.1G 'Hz/V' =kvco
2 =m
8 =n
1.4pF =cs
59.7pF =cp
2.2kOhms =rz

EC also takes commands from the command line. For example:

$ ec -x "125mV 67uV / db"

The -x tells ec to print out the value of the x register when it terminates. Without it you would not see the result.

EC prints back-quoted strings while interpolating the values of registers and variables when requested. For example:

$ ec 'degs 500 1000 rtop "V/V" `Gain = $0 @ $1.`'
Gain = 1.118 KV/V @ 26.565 degs.

You can get a list of the actions available with:

0: ?

You can get help on a specific topic, such as //, with:

0: ?//

You can get a list of the help topics available with:

0: help

There is much more available that what is described here. For more information, run:

$ man ec

You can quit the program using:

0: quit

(or :q or ^C).