engineering-calculator


Nameengineering-calculator JSON
Version 1.10 PyPI version JSON
download
home_pagehttps://engineering-calculator.readthedocs.io/en/latest/
Summaryengineering calculator
upload_time2022-12-28 04:21:38
maintainer
docs_urlNone
authorKen Kundert
requires_python>=3.6
licenseGPLv3
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            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.


Installing
----------

| Version: 1.10
| Released: 2022-12-27

.. image:: https://pepy.tech/badge/ec/month
    :target: https://pepy.tech/project/ec

..  image:: https://github.com/KenKundert/ec/actions/workflows/build.yaml/badge.svg
    :target: https://github.com/KenKundert/ec/actions/workflows/build.yaml

.. image:: https://img.shields.io/readthedocs/engineering_calculator.svg
   :target: https://engineering_calculator.readthedocs.io/en/latest/?badge=latest

.. image:: https://img.shields.io/pypi/v/engineering_calculator.svg
    :target: https://pypi.python.org/pypi/engineering_calculator

.. image:: https://img.shields.io/pypi/pyversions/engineering_calculator.svg
    :target: https://pypi.python.org/pypi/engineering_calculator


Requires Python version 3.6 or later.

Install with::

    pip3 install --user engineering-calculator

This installs *ec* into ~/.local/bin, which should be added to your path.

Unusually, there is also a man page.  The Python install process no longer 
supports man pages, however you can download it from `GitHub 
<https://raw.githubusercontent.com/KenKundert/ec/master/doc/ec.1>`_.  Place it 
in ``~/.local/man/man1``.

More information on both *ec* can be found on `ReadTheDocs 
<https://engineering-calculator.readthedocs.io>`_ .


Installing from Source
----------------------

To get the source code::

   $ git clone https://github.com/KenKundert/ec.git

Once cloned, you can get the latest updates using::

   $ cd ec
   $ git pull

To run the regression tests::

   $ tox

To install::

   $ python setup.py install --user

To run EC::

   $ ec
   0:


Installing Man Page
-------------------

If you have installed from source, you can install the manpage with::

    cd doc
    make publish

Otherwise, you can install the latest version of the manpage on GitHub using::

    curl https://raw.githubusercontent.com/KenKundert/ec/master/install-manpage | bash -

Once installed, you can get access the man page using::

    man ec


A Brief Tour of Engineering Calculator
--------------------------------------

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 +
   9:

This command first pushes 4 onto the stack, then it pushes 5 on the stack, and 
finally runs the addition operator, which pulls 4 and 5 off the stack and then 
pushes the sum, 9, back onto the stack.  The prompt displays the value of the 
x-register, which is generally the final result from the previous command.

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

   0: 4 5 + 6 7 + *
   117:

This command demonstrates the power of using a stack for calculations. It first 
computes the sum and places the results on the stack. That result stays on the 
stack while the sum of 6 and 7 is computed, and finally it is used, and 
consumed, in the final multiplication.

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

   0: 100
   100: 100
   100: ||
   50:

Effectively, you only need to type *enter* is when you want to see the result.

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+ *
   220:

Use *stack* to see the contents of the stack::

   0: 1 2 3 4 5 stack
        1
        2
        3
     y: 4
     x: 5
   5: + stack
        1
        2
     y: 3
     x: 9
   9: + stack
        1
     y: 2
     x: 12
   12: + stack
     y: 1
     x: 14
   14: + stack
     x: 15
   14: -1 stack
     y: 15
     x: -1
   -1:

The stack grows without limit as needed. The bottom two values are the values 
that are generally involved in operations and they are labeled *x* and *y* as an 
aid to help you understand and predict the basic operation of various commands. 
For example::

   0: 8 2 stack
     y: 8
     x: 2
   2: ytox
   64:

The command name *ytox* is short for 'raise value of *y* register to the value 
in the *x* register'.

You remove a value from the bottom of the stack with *pop*::

   0: 10 -3 stack
     y: 10
     x: -3
   -3: pop
   10: stack
     x: 10

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/
   1.5915K:

Display variables using::

   628.32M: vars
     Cin = 1pF
     Rref = 50 Ohms
     freq = 100MHz
     omega = 628.32M
   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.

From the above example you can see that EC supports SI scale factors and units.  
The support for units is relatively conservative.  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 /
   100M:

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.

This simple way of adding units to a number, ex. 100MHz, is somewhat restricted.

* You can only add units after a scale factor, but once you've given the scale 
  factor the units are optional. In this way, 1m represents 1e-3 rather than one 
  meter. If you want to specify one meter, you would use 1_m. The underscore is 
  a scale factor, like m or k. It represents the unity scale factor.

* Units added to the end of a number may consist only of letters and 
  underscores. Digits and special characters like /, ^, \*, -, ( or ) are not 
  allowed.

* You can only add units to number literals. So 100MHz is okay, but 'omega 2pi/ 
  Hz' is not.

You can overcome this limitation by entering a quoted string. Doing so 
interprets the contents of the string as units and applies them to whatever is 
in the *x* register. For example::

   0: 100MHz 2pi* "rads/s"
   628.32 Mrads/s: 2pi / "Hz"
   100 MHz:

   0: 9.8066 "m/s^2"
   9.8066 m/s^2:

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

   0: $100M
   $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
   15:

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
   'b11111111:

You can convert voltages into *dBm* using::

   0: 10 vdbm
   30:

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::

    eng6
    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 "125mV 67uV / db"
   65.417

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.` quit'
   Gain = 1.118 KV/V @ 26.565 degs.

Normally *ec* prints the value of the x register and exits when it runs out of 
things to do.  The *quit* at the end tells ec to exit immediately. In this way 
the value of the x register is not printed.  Without it you would see the 
magnitude printed twice.

You can define functions with the following syntax: *( ... )name*, where '(' 
starts the function definition, ')name' terminates it, and ... is simply 
a collection of calculator actions. For example::

   0: (2pi * "rads/s")to_omega
   0: (2pi / "Hz")to_freq
   0: 1.4GHz
   1.4 GHz: to_omega
   8.7965 Grads/s: to_freq
   1.4 GHz:

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. If you have installed 
the man-page, you can get more information by running::

   $ man ec

Alternately, you can view the `online documentation 
<https://engineering-calculator.readthedocs.io>`_.

You can quit the program using::

   0: quit

(or *:q* or *^D*).

More detailed information can be found `here 
<https://nurdletech.com/linux-utilities/ec/ec.html>`_.

            

Raw data

            {
    "_id": null,
    "home_page": "https://engineering-calculator.readthedocs.io/en/latest/",
    "name": "engineering-calculator",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "Ken Kundert",
    "author_email": "ec@nurdletech.com",
    "download_url": "https://files.pythonhosted.org/packages/9e/ae/bd88fda1996b31899163902698f8d8d1433fcb23238537de9dd25831f6d6/engineering-calculator-1.10.tar.gz",
    "platform": null,
    "description": "ec: An Engineering Calculator\n=============================\n\nThis calculator is noteworthy in that it employs a stack model of computation \n(Reverse Polish Notation), it supports numbers with SI scale factors and units. \nand uses a text-only user interface.\n\n\nInstalling\n----------\n\n| Version: 1.10\n| Released: 2022-12-27\n\n.. image:: https://pepy.tech/badge/ec/month\n    :target: https://pepy.tech/project/ec\n\n..  image:: https://github.com/KenKundert/ec/actions/workflows/build.yaml/badge.svg\n    :target: https://github.com/KenKundert/ec/actions/workflows/build.yaml\n\n.. image:: https://img.shields.io/readthedocs/engineering_calculator.svg\n   :target: https://engineering_calculator.readthedocs.io/en/latest/?badge=latest\n\n.. image:: https://img.shields.io/pypi/v/engineering_calculator.svg\n    :target: https://pypi.python.org/pypi/engineering_calculator\n\n.. image:: https://img.shields.io/pypi/pyversions/engineering_calculator.svg\n    :target: https://pypi.python.org/pypi/engineering_calculator\n\n\nRequires Python version 3.6 or later.\n\nInstall with::\n\n    pip3 install --user engineering-calculator\n\nThis installs *ec* into ~/.local/bin, which should be added to your path.\n\nUnusually, there is also a man page.  The Python install process no longer \nsupports man pages, however you can download it from `GitHub \n<https://raw.githubusercontent.com/KenKundert/ec/master/doc/ec.1>`_.  Place it \nin ``~/.local/man/man1``.\n\nMore information on both *ec* can be found on `ReadTheDocs \n<https://engineering-calculator.readthedocs.io>`_ .\n\n\nInstalling from Source\n----------------------\n\nTo get the source code::\n\n   $ git clone https://github.com/KenKundert/ec.git\n\nOnce cloned, you can get the latest updates using::\n\n   $ cd ec\n   $ git pull\n\nTo run the regression tests::\n\n   $ tox\n\nTo install::\n\n   $ python setup.py install --user\n\nTo run EC::\n\n   $ ec\n   0:\n\n\nInstalling Man Page\n-------------------\n\nIf you have installed from source, you can install the manpage with::\n\n    cd doc\n    make publish\n\nOtherwise, you can install the latest version of the manpage on GitHub using::\n\n    curl https://raw.githubusercontent.com/KenKundert/ec/master/install-manpage | bash -\n\nOnce installed, you can get access the man page using::\n\n    man ec\n\n\nA Brief Tour of Engineering Calculator\n--------------------------------------\n\nTo perform operations in EC, you first enter the numbers, then the operators.  \nIn particular, as you enter the numbers they are pushed onto the stack. The \noperators then take numbers from the stack and replace them with the result.  \nThe operations are performed immediately and there is no use of parentheses to \ngroup calculations. Any intermediate results are stored on the stack until \nneeded.\n\nTo add two numbers::\n\n   0: 4 5 +\n   9:\n\nThis command first pushes 4 onto the stack, then it pushes 5 on the stack, and \nfinally runs the addition operator, which pulls 4 and 5 off the stack and then \npushes the sum, 9, back onto the stack.  The prompt displays the value of the \nx-register, which is generally the final result from the previous command.\n\nYou can string together an arbitrarily long calculation on a single line::\n\n   0: 4 5 + 6 7 + *\n   117:\n\nThis command demonstrates the power of using a stack for calculations. It first \ncomputes the sum and places the results on the stack. That result stays on the \nstack while the sum of 6 and 7 is computed, and finally it is used, and \nconsumed, in the final multiplication.\n\nAlternately, you can string a calculation over multiple lines (this calculates \nthe value of two parallel 100 ohm resistors)::\n\n   0: 100\n   100: 100\n   100: ||\n   50:\n\nEffectively, you only need to type *enter* is when you want to see the result.\n\nSelect operators can be entered without preceding them with a space if they \nfollow a number or a name. For example::\n\n   0: 4 5* 6 5+ *\n   220:\n\nUse *stack* to see the contents of the stack::\n\n   0: 1 2 3 4 5 stack\n        1\n        2\n        3\n     y: 4\n     x: 5\n   5: + stack\n        1\n        2\n     y: 3\n     x: 9\n   9: + stack\n        1\n     y: 2\n     x: 12\n   12: + stack\n     y: 1\n     x: 14\n   14: + stack\n     x: 15\n   14: -1 stack\n     y: 15\n     x: -1\n   -1:\n\nThe stack grows without limit as needed. The bottom two values are the values \nthat are generally involved in operations and they are labeled *x* and *y* as an \naid to help you understand and predict the basic operation of various commands. \nFor example::\n\n   0: 8 2 stack\n     y: 8\n     x: 2\n   2: ytox\n   64:\n\nThe command name *ytox* is short for 'raise value of *y* register to the value \nin the *x* register'.\n\nYou remove a value from the bottom of the stack with *pop*::\n\n   0: 10 -3 stack\n     y: 10\n     x: -3\n   -3: pop\n   10: stack\n     x: 10\n\nTo store a value into a variable, type an equal sign followed by a name. To\nrecall it, simply use the name::\n\n   0: 100MHz =freq\n   100MHz: 2pi* =omega\n   628.32M: 1pF =Cin\n   1pF: 1 omega/ Cin/\n   1.5915K:\n\nDisplay variables using::\n\n   628.32M: vars\n     Cin = 1pF\n     Rref = 50 Ohms\n     freq = 100MHz\n     omega = 628.32M\n   628.32M:\n\n*Rref* is a special variable that is set by default to 50 Ohms, but you can \nchange its value. It is used in *dBm* calculations.\n\nFrom the above example you can see that EC supports SI scale factors and units.  \nThe support for units is relatively conservative.  You can enter them\nand it remembers them, but they do not survive any operation other than a\ncopy. In this way it should never display incorrect or misleading units, however\nit displays units when it can. For example::\n\n   0: 100MHz =freq\n   100 MHz: 2pi* \"rads/s\" =omega\n   628.32 Mrads/s: vars\n     Rref = 50 Ohms\n     freq = 100 MHz\n     omega = 628.32 Mrads/s\n   628.32 Mrads/s: 2pi /\n   100M:\n\nNotice that EC captured units on 100MHz and stored them into the memory freq.\nAlso notice that the units of \"rads/s\" were explicitly specified, and they were\nalso captured. Finally, notice that dividing by *2pi* cleared the units.\n\nThis simple way of adding units to a number, ex. 100MHz, is somewhat restricted.\n\n* You can only add units after a scale factor, but once you've given the scale \n  factor the units are optional. In this way, 1m represents 1e-3 rather than one \n  meter. If you want to specify one meter, you would use 1_m. The underscore is \n  a scale factor, like m or k. It represents the unity scale factor.\n\n* Units added to the end of a number may consist only of letters and \n  underscores. Digits and special characters like /, ^, \\*, -, ( or ) are not \n  allowed.\n\n* You can only add units to number literals. So 100MHz is okay, but 'omega 2pi/ \n  Hz' is not.\n\nYou can overcome this limitation by entering a quoted string. Doing so \ninterprets the contents of the string as units and applies them to whatever is \nin the *x* register. For example::\n\n   0: 100MHz 2pi* \"rads/s\"\n   628.32 Mrads/s: 2pi / \"Hz\"\n   100 MHz:\n\n   0: 9.8066 \"m/s^2\"\n   9.8066 m/s^2:\n\nNormally units are given after the number, however a dollar sign would be given\nimmediately before::\n\n   0: $100M\n   $100M:\n\nYou can enter hexadecimal, octal, or binary numbers, in either traditional\nprogrammers notation or in Verilog notation. For example::\n\n   0: 0xFF\n   255: 0o77\n   63: 0b1111\n   15: 'hFF\n   255: 'o77\n   63: 'b1111\n   15:\n\nYou can also display numbers in hexadecimal, octal, or binary in both\ntraditional or Verilog notation. To do so, use ``hex``, ``oct``, ``bin``, \n``vhex``, ``voct``, or ``vbin``::\n\n   0: 255\n   255: hex4\n   0x00ff: vbin\n   'b11111111:\n\nYou can convert voltages into *dBm* using::\n\n   0: 10 vdbm\n   30:\n\nYou can convert *dBm* into voltage using::\n\n   0: -10 dbmv\n   100 mV: \n\nBoth of these assume a load resistance that is contained in memory *Rref*, which \nby default is 50 Ohms.\n\nAt start up EC reads and executes commands from files. It first tries '~/.ecrc'\nand runs any commands it contains if it exists. It then tries './.ecrc' if it\nexists. Finally it runs any files given on the command line. It is common to put\nyour generic preferences in '~/.exrc'. For example, if your are a physicist with\na desire for high precision results, you might use::\n\n    eng6\n    h 2pi / \"J-s\" =hbar\n\nThis tells EC to use 6 digits of resolution and predefines *hbar* as a constant.\nThe local start up file ('./.ecrc') or the file given as a command line argument\nis generally used to give more project specific initializations. For example, in\na directory where you are working on a PLL design you might have an './.ecrc'\nfile with the following contents::\n\n    88.3uSiemens =kdet\n    9.1G \"Hz/V\" =kvco\n    2 =m\n    8 =n\n    1.4pF =cs\n    59.7pF =cp\n    2.2kOhms =rz\n\nEC also takes commands from the command line. For example::\n\n   $ ec \"125mV 67uV / db\"\n   65.417\n\nEC prints back-quoted strings while interpolating the values of registers and \nvariables when requested. For example::\n\n   $ ec 'degs 500 1000 rtop \"V/V\" `Gain = $0 @ $1.` quit'\n   Gain = 1.118 KV/V @ 26.565 degs.\n\nNormally *ec* prints the value of the x register and exits when it runs out of \nthings to do.  The *quit* at the end tells ec to exit immediately. In this way \nthe value of the x register is not printed.  Without it you would see the \nmagnitude printed twice.\n\nYou can define functions with the following syntax: *( ... )name*, where '(' \nstarts the function definition, ')name' terminates it, and ... is simply \na collection of calculator actions. For example::\n\n   0: (2pi * \"rads/s\")to_omega\n   0: (2pi / \"Hz\")to_freq\n   0: 1.4GHz\n   1.4 GHz: to_omega\n   8.7965 Grads/s: to_freq\n   1.4 GHz:\n\nYou can get a list of the actions available with::\n\n   0: ?\n\nYou can get help on a specific topic, such as //, with::\n\n   0: ?//\n\nYou can get a list of the help topics available with::\n\n   0: help\n\nThere is much more available that what is described here. If you have installed \nthe man-page, you can get more information by running::\n\n   $ man ec\n\nAlternately, you can view the `online documentation \n<https://engineering-calculator.readthedocs.io>`_.\n\nYou can quit the program using::\n\n   0: quit\n\n(or *:q* or *^D*).\n\nMore detailed information can be found `here \n<https://nurdletech.com/linux-utilities/ec/ec.html>`_.\n",
    "bugtrack_url": null,
    "license": "GPLv3",
    "summary": "engineering calculator",
    "version": "1.10",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "51fdba92aae1df684e4915ee9a145139",
                "sha256": "de9737b9ef167b118fad14480285ad3366426c044f4f7d2e604c91b77e9b3ec8"
            },
            "downloads": -1,
            "filename": "engineering_calculator-1.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "51fdba92aae1df684e4915ee9a145139",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 52451,
            "upload_time": "2022-12-28T04:21:37",
            "upload_time_iso_8601": "2022-12-28T04:21:37.192054Z",
            "url": "https://files.pythonhosted.org/packages/8c/8b/3a7156e56d5291a1175a5061c8edaf1cc9e4be64df9d8611a4fe272187a4/engineering_calculator-1.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "c6a93d2197adf12820e2fd35cf5079ee",
                "sha256": "eb5b33b9e5a1497469c773cc644d1f36c06a274414a1556a2b4e9255aaf76c52"
            },
            "downloads": -1,
            "filename": "engineering-calculator-1.10.tar.gz",
            "has_sig": false,
            "md5_digest": "c6a93d2197adf12820e2fd35cf5079ee",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 55026,
            "upload_time": "2022-12-28T04:21:38",
            "upload_time_iso_8601": "2022-12-28T04:21:38.873903Z",
            "url": "https://files.pythonhosted.org/packages/9e/ae/bd88fda1996b31899163902698f8d8d1433fcb23238537de9dd25831f6d6/engineering-calculator-1.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-28 04:21:38",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "engineering-calculator"
}
        
Elapsed time: 0.06711s