{"id":24122191,"url":"https://github.com/tlinden/rpnc","last_synced_at":"2025-09-18T11:32:52.147Z","repository":{"id":144613080,"uuid":"171046442","full_name":"TLINDEN/rpnc","owner":"TLINDEN","description":"Programmable command-line calculator using reverse polish notation","archived":false,"fork":false,"pushed_at":"2025-08-08T11:16:15.000Z","size":7622,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-08T12:27:02.706Z","etag":null,"topics":["calc","cli","command-line","golang","linux-shell","math","programmable","reverse-polish-calculator","reverse-polish-notation","rpn","rpn-calculator","shell","terminal"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TLINDEN.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-02-16T20:05:45.000Z","updated_at":"2025-08-08T11:13:49.000Z","dependencies_parsed_at":"2025-01-11T11:39:09.677Z","dependency_job_id":"99796a7a-a18f-4785-9ca3-c580b36e0682","html_url":"https://github.com/TLINDEN/rpnc","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/TLINDEN/rpnc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TLINDEN%2Frpnc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TLINDEN%2Frpnc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TLINDEN%2Frpnc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TLINDEN%2Frpnc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TLINDEN","download_url":"https://codeload.github.com/TLINDEN/rpnc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TLINDEN%2Frpnc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275757846,"owners_count":25523112,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-18T02:00:09.552Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["calc","cli","command-line","golang","linux-shell","math","programmable","reverse-polish-calculator","reverse-polish-notation","rpn","rpn-calculator","shell","terminal"],"created_at":"2025-01-11T11:38:52.915Z","updated_at":"2025-09-18T11:32:52.132Z","avatar_url":"https://github.com/TLINDEN.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Programmable command-line calculator using reverse polish notation\n\n[![Actions](https://github.com/tlinden/rpnc/actions/workflows/ci.yaml/badge.svg)](https://github.com/tlinden/rpnc/actions)\n[![License](https://img.shields.io/badge/license-GPL-blue.svg)](https://github.com/tlinden/rpnc/blob/master/LICENSE)\n[![Go Report Card](https://goreportcard.com/badge/github.com/tlinden/rpnc)](https://goreportcard.com/report/github.com/tlinden/rpnc) \n\nThis is a small commandline calculator which takes its input in\n[reverse polish notation](https://en.wikipedia.org/wiki/Reverse_Polish_notation)\nform.\n\nFeatures:\n\n- unlimited stack\n- undo\n- various stack manipulation commands\n- basic math operators\n- advanced math functions (not yet complete)\n- can be used on the commandline\n- can calculate data in batch mode (also from STDIN)\n- extensible with custom LUA functions\n- provides interactive repl\n- completion\n- history\n- comments (comment character is `#`)\n- variables\n- help screen uses comfortable internal pager\n\n## Demo\n\n![asciicast](demo/demo.gif)\n\n## Working principle\n\nReverse Polish  Notation (short: RPN)  requires to have a  stack where\nnumbers and results are being put.  So, you put numbers onto the stack\nand each math  operation uses these for calculation,  removes them and\nputs the result  back.\n\nTo visualize it, let's look at a calculation:\n\n    ((80 + 20) / 2) * 4\n    \nThis is how  you enter the formula  int an RPN calculator  and how the\nstack evolves during the operation:\n\n| rpn commands | stack contents | calculation   |\n|--------------|----------------|---------------|\n|           80 |             80 |               |\n|           20 |          80 20 |               |\n|            + |            100 | 80 + 20 = 100 |\n|            2 |          100 2 |               |\n|            / |             50 | 100 / 2 = 50  |\n|            4 |           50 4 |               |\n|            x |            200 | 50 * 4 = 200  |\n\nThe last stack element 200 is the calculation result. This is how it looks with debugging enabled in `rpn`:\n\n```\nrpn-\u003edebug [0/rev0]» 80 20 + 2 / 4 x\nDEBUG(000):      push to stack: 80.00\nDEBUG(001):      push to stack: 20.00\nDEBUG(002):  remove from stack: 20.00\nDEBUG(003):  remove from stack: 80.00\nDEBUG(calc): evaluating: 80.00 + 20.00\nDEBUG(004):      push to stack: 100.00\n= 100\nDEBUG(005):      push to stack: 2.00\nDEBUG(006):  remove from stack: 2.00\nDEBUG(007):  remove from stack: 100.00\nDEBUG(calc): evaluating: 100.00 / 2.00\nDEBUG(008):      push to stack: 50.00\n= 50\nDEBUG(009):      push to stack: 4.00\nDEBUG(010):  remove from stack: 4.00\nDEBUG(011):  remove from stack: 50.00\nDEBUG(calc): evaluating: 50.00 x 4.00\nDEBUG(012):      push to stack: 200.00\n= 200\n```\n\nFor a very good explanation how reverse polish notation and the stack works [watch this video by Prof. Brailsford](https://youtu.be/7ha78yWRDlE?si=9MCp59jAAG8fXavP)\n\n## Usage\n\nBasically   you  enter   numbers  followed   by  an   operator  or   a\nfunction. Each number you enter will be put into the stack. Say you\nentered two numbers, 2 and 4. If you now enter the `+` operator, those\ntwo numbers will be removed from the stack, added and the result will\nbe put back onto the stack.\n\nHere's a  comprehensive example:  calculate the summary  resistance of\nparallel  resistors with  220, 330  and  440 Ohm  using the  following\nformula:\n\n    1 / (1/R1 + 1/R2 + 1/R3)\n\nHere's the sample session:\n\n```\nrpn [0]» 1\nrpn [1]» 1 220 /\n= 0.004545454545454545\nrpn [2]» 1 330 /\n= 0.0030303030303030303\nrpn [3]» 1 440 /\n= 0.0022727272727272726\nrpn [4]» +\n= 0.0053030303030303025\nrpn [3]» +\n= 0.009848484848484848\nrpn [2]» /\n= 101.53846153846155\n```\n\nIt doesn't matter  wether you enter numbers  and operators/function on\nthe same line or separated by whitespace:\n\n```\nrpn [0]» 1 1 220 / 1 330 / 1 440 / + + /\n= 0.004545454545454545\n= 0.0030303030303030303\n= 0.0022727272727272726\n= 0.0053030303030303025\n= 0.009848484848484848\n= 101.53846153846155\n```\n\nWorks on the commandline as well:\n\n```\nrpn 1 1 220 / 1 330 / 1 440 / + + /\n0.004545454545454545\n0.0030303030303030303\n0.0022727272727272726\n0.0053030303030303025\n0.009848484848484848\n101.53846153846155\n```\n\nAnd via STDIN:\n```\necho \"1 1 220 / 1 330 / 1 440 / + + /\" | rpn\n0.004545454545454545\n0.0030303030303030303\n0.0022727272727272726\n0.0053030303030303025\n0.009848484848484848\n101.53846153846155\n```\n\nWhat we basically entered was:\n\n    1 1 220 / 1 330 / 1 440 / + + /\n    \nWhich translates to:\n\n    1 ((1 / 220) + (1 / 330) + (1 / 440))\n    \nSo,  you're entering  the numbers  and operators  as you  would do  on\npaper. To learn more, refer to the Wikipedia page linked above.\n\n## Batch mode\n\nBeside  traditional RPN  you can  also  enter a  special mode,  called\n*batch  mode* either  by entering  the  `batch` command  or using  the\ncommandline  switch \u003ckbd\u003e-b\u003c/kbd\u003e.\n\nMost  operators and  functions can  be used  with batch  mode but  not\nall. In this mode the calculation works on all numbers on the stack so\nfar.\n\nSo, let's compare. If you had in normal RPN mode the following stack:\n\n    3\n    5\n    6\n    \nand then enter  the \u003ckbd\u003e+\u003c/kbd\u003e operator, the calculator  would pop 5\nand 6  from the stack,  add them  and push the  result 11 back  to the\nstack.\n\nHowever, if  you are in  batch mode, then  all the items  would be\nadded, the sub stack would be cleared and the result 14 would be added\nto the stack.\n\nTo leave batch mode just enter the `batch` command again (this is a\ntoggle).\n\nHere's an example using a math function:\n\n    echo 1 2 3 4 5 6 7 | rpn -b median\n    4\n\nReally simple.\n\n## Undo\n\nEvery operation which  modifies the stack can be  reversed by entering\nthe `undo` command. There's only one level of undo and no redo.\n\n## Extend the calculator with LUA functions\n\nYou can use a lua script with lua functions to extend the\ncalculator. By default the tool looks for `~/.rpn.lua`. You can also\nspecify a script using the \u003ckbd\u003e-c\u003c/kbd\u003e flag.\n\nHere's an example of such a script:\n\n```lua\nfunction add(a,b)\n  return a + b\nend\n\nfunction init()\n  register(\"add\", 2, \"addition\")\nend\n```\n\nHere  we created  a function  `add()` which  adds two  parameters. All\nparameters are `FLOAT64` numbers. You  don't have to worry about stack\nmanagement, this is taken care of automatically.\n\nThe function `init()` **MUST** be defined, it will be called on\nstartup. You can do anything you like in there, but you need to call\nthe `register()` function to register your functions to the\ncalculator. This function takes these parameters:\n\n- function name\n- number of arguments expected (see below)\n- help text\n\nNumber of expected arguments can be:\n\n- 0: expect 1 argument but do NOT modify the stack\n- 1-n: do a singular calculation\n- -1: batch mode work with all numbers on the stack \n\nPlease [refer to the lua language\nreference](https://www.lua.org/manual/5.4/) for more details about\nLUA.\n\n**Please note, that io, networking and system stuff is not allowed\nthough. So you can't open files, execute other programs or open a\nconnection to the outside!**\n\n## Installation\n\nThere are multiple ways to install **rpn**:\n\n- Go to the [latest release page](https://github.com/tlinden/rpn/releases/latest),\n  locate the binary for your operating system and platform.\n  \n  Download it and put it into some directory within your `$PATH` variable.\n  \n- The release page also contains a tarball for every supported platform. Unpack it\n  to some temporary directory, extract it and execute the following command inside:\n  ```\n  sudo make install\n  ```\n  \n- You can also install from source. Issue the following commands in your shell:\n  ```\n  git clone https://github.com/TLINDEN/rpn.git\n  cd rpn\n  make\n  sudo make install\n  ```\n\nIf you  do not find a  binary release for your  platform, please don't\nhesitate to ask me about it, I'll add it.\n\n\n## Documentation\n\nThe  documentation  is  provided  as  a unix  man-page.   It  will  be\nautomatically installed if  you install from source.  However, you can\n[read the man-page online](https://github.com/TLINDEN/rpnc/blob/master/rpn.pod)\n\nOr if you cloned  the repository you can read it  this way (perl needs\nto be installed though): `perldoc rpn.pod`.\n\nIf you have the binary installed, you  can also read the man page with\nthis command:\n\n    rpn --man\n\n## Getting help\n\nAlthough I'm happy to hear from rpn users in private email, that's the\nbest way for me to forget to do something.\n\nIn order to report a bug,  unexpected behavior, feature requests or to\nsubmit    a    patch,    please    open   an    issue    on    github:\nhttps://github.com/TLINDEN/rpnc/issues.\n\n## Copyright and license\n\nThis software is licensed under the GNU GENERAL PUBLIC LICENSE version 3.\n\n## Authors\n\nT.v.Dein \u003ctom AT vondein DOT org\u003e\n\n## Project homepage\n\nhttps://github.com/TLINDEN/rpnc\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftlinden%2Frpnc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftlinden%2Frpnc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftlinden%2Frpnc/lists"}