Author Topic: command line calculator  (Read 1609 times)

0 Members and 2 Guests are viewing this topic.

Offline rfclownTopic starter

  • Frequent Contributor
  • **
  • Posts: 412
  • Country: us
command line calculator
« on: July 09, 2022, 01:32:26 am »
1. I am an electrical engineer and I often want to use a calculator
2. A calculator is not always at my side (or I'm too lazy to look for it)
3. I am often at a computer when I want to use a calculator
4. I HATE every computer calculator that I have tried because... a mouse is the WORST POSSIBLE interface device for a calculator
5. I wrote a C program calculator in 2002 or so, and have used it ever since

I'm not an RPN calculator fan; I've never bought one. The calculator on my desk at the moment is a Casio fx-115ES. But a brain dead person can write a program for an RPN calculator since it puts all the burden of figuring out order of operation on the user, so that's what I did. I started it around 2002, and tweaked things in 2003. I made it so I could easily add functions. The last time I added a function was 2005, so it's been pretty useful to me as it was 17 years ago. When I first wrote it I used whatever C compiler was on my Unix workstation (at work), and used Power C (Mix Software) on my PC at home. Now I use gcc. This is one my MUST have programs when I set up a new computer. Hopefully C will be forever and I can just recompile for the rest of my life (I'm 60 years old and hopeful that C won't die).

At one point I added a thing where I could read in a list of operations from a file. Turns out I never use it. For the things I might have thought I'd use it for, I use Excel. A spreadsheet is an AWESOME tool. A calculator is an AWESOME tool. Let the quickest one for the particular problem win. A calculator with a mouse interface will always lose.

For any computer I use I make a quick way to open a terminal. Some things are better and faster with a command line interface, and some things are better and faster with a GUI. I name my program executable "ca" (although I called it ccalc when I developed it), so I just open a terminal and type "ca". Calculate, done. To build the calculator, first compile bcl.c, then run bcl, then compile ccalc.c. The steps using gcc are in the batch file j.bat are are:

gcc bcl.c -o bcl
bcl
gcc ccalc.c -o ccalc

-edit. added exe compiled on a Win7 PC
-edit. replaced files with bug fix. exe in source zip file
« Last Edit: July 09, 2022, 08:20:53 pm by rfclown »
 
The following users thanked this post: evb149

Offline rfclownTopic starter

  • Frequent Contributor
  • **
  • Posts: 412
  • Country: us
Re: command line calculator
« Reply #1 on: July 09, 2022, 02:47:42 am »
...Or running octave from the command line.


If I had learned about that earlier (if it existed earlier), that's what I might be using. I've just recently gotten octave because I work with people who use Matlab. I use octave to figure out how to do someone's Matlab routine in LabVIEW. Today I looked at someones Matlab routine to do a Welch periodogram for computing noise power spectral density so I could code it in LabVIEW. My computing tools of choice are LabVIEW, Excel, a calculator, and C (whichever is best for the task). I disregarded Matlab years ago because of the speed, but never considered it for just using as a calculator. With LabVIEW I can stream in data and perform computations in real time; Matlab (octave), not so.
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3109
  • Country: us
Re: command line calculator
« Reply #2 on: July 09, 2022, 02:52:06 am »
You might be interested in the venerable "bc" Unix/Linux command. It ticks the following boxes:

- command line oriented
- conventional algebraic notation
- arbitrary precision calculations
- can operate in bases 2 through 16
- user can define custom functions
- a standard Unix/Linux command found in every distro

This video is the best one I found which demonstrates its use:

Mathematical Calculations in Linux | bc calculator in linux | programming features of bc calculator
https://youtu.be/B5HrLg2gu9o


 

Offline rfclownTopic starter

  • Frequent Contributor
  • **
  • Posts: 412
  • Country: us
Re: command line calculator
« Reply #3 on: July 09, 2022, 02:53:03 am »
Oh maybe you'd be interested to share your tool via something like github, bitbucket, et. al. ?
Then more people will likely be able to find and most easily pull / use it, given you include your description for its function / purpose / use and pick some reasonable open license for it, BSD or whatever.

https://bitbucket.org/
https://github.com/
et. al.

I probably should learn to use one of these types of sharing resources. This isn't something I'm trying to promote or devote time to (haven't changed it since 2005). But I have benefited from finding things others have done on things like github. I just had a random thought at the moment to post it somewhere, and this forum is a painless why to do it.
 

Offline rfclownTopic starter

  • Frequent Contributor
  • **
  • Posts: 412
  • Country: us
Re: command line calculator
« Reply #4 on: July 09, 2022, 03:00:25 am »
You might be interested in the venerable "bc" Unix/Linux command. It ticks the following boxes:

- command line oriented
- conventional algebraic notation
- arbitrary precision calculations
- can operate in bases 2 through 16
- user can define custom functions
- a standard Unix/Linux command found in every distro

This video is the best one I found which demonstrates its use:

Mathematical Calculations in Linux | bc calculator in linux | programming features of bc calculator
https://youtu.be/B5HrLg2gu9o

Back when my main work computer was Unix (along time ago) I looked at bc. It never caught on with me. I've been on a PC mostly the last bazillion years. Some of the stuff I wanted in a calculator was the ability to work with complex numbers, and to add functions/conversions that I use often like peak to and from RMS, dB to volts to watts, etc.
 

Offline Alex Eisenhut

  • Super Contributor
  • ***
  • Posts: 3374
  • Country: ca
  • Place text here.
Re: command line calculator
« Reply #5 on: July 09, 2022, 04:57:14 am »
Learn APL?

Hoarder of 8-bit Commodore relics and 1960s Tektronix 500-series stuff. Unconventional interior decorator.
 

Offline NiHaoMike

  • Super Contributor
  • ***
  • Posts: 9154
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
Re: command line calculator
« Reply #6 on: July 09, 2022, 05:06:29 am »
Cryptocurrency has taught me to love math and at the same time be baffled by it.

Cryptocurrency lesson 0: Altcoins and Bitcoin are not the same thing.
 
The following users thanked this post: rfclown

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3109
  • Country: us
Re: command line calculator
« Reply #7 on: July 09, 2022, 03:24:20 pm »
Have you tried Speedcrunch?
https://heldercorreia.bitbucket.io/speedcrunch/

Of potential interest to the OP, Speedcrunch supports complex numbers. Use the menu option Settings ->  Behavior -> Enable Complex Numbers and then "j" is interpreted as the imaginary unit.
 
The following users thanked this post: rfclown

Offline rfclownTopic starter

  • Frequent Contributor
  • **
  • Posts: 412
  • Country: us
Re: command line calculator
« Reply #8 on: July 09, 2022, 03:58:20 pm »
Have you tried Speedcrunch?
https://heldercorreia.bitbucket.io/speedcrunch/

That looks cool. I'll download and check it out. When I did my calculator I thought it would be useful to make it "programable", so I added the < function which enters commands from a file. I never use that. The files are then cryptic to read because they are RPN entries. Turns out that anything more than quick calculations is better done with a tool other than a calculator. But for my calculator, I want it to be quick to type, so something like peak-to-rms is just p2r. I put in all the things I do often volts-to-watts (v2w), things like that. I thought I'd keep adding functions, but I guess what I had in 2005 has served me well so far.
 

Offline rfclownTopic starter

  • Frequent Contributor
  • **
  • Posts: 412
  • Country: us
Re: command line calculator
« Reply #9 on: July 09, 2022, 05:51:55 pm »
Downloaded speedcrunch. Looks good.

Found a bug in my code. That's what I get for posting something I've used unchanged for 17 years. I was looking through all the functions, and didn't realize I had "db" and "dbv". I've been doing that manually for years (for db entering something like "5.6 .05 log 10*" dbv is the same but does 20*log10(y/x), so I call the db function then multiply by two, but I had a typo and the two was "2,0" and not "2.0". Guess I didn't check the function when I coded it. O well. I guess I'm no better than many of the software guys at my day job who compile and throw it over the wall to the hardware guys. I've gotten stuff that doesn't even run; they didn't even try to run it, let alone see if it does what it's supposed to do.
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14892
  • Country: fr
Re: command line calculator
« Reply #10 on: July 09, 2022, 05:59:21 pm »
I've mentioned "calc" in previous threads. It's exactly that, a console calculator. It's arbitrary-precision, supports an internal language close to C (but interpreted), and that's what I've used for years.
http://www.isthe.com/chongo/tech/comp/calc/index.html
source code: http://www.isthe.com/chongo/src/calc/

(It builds fine on Linux but the latest versions have unfortunately become a bit hard to build on Windows, even using MSYS2. Maybe the authors have fixed this though.)

(I more recently worked on my own calculator app, also with a 'console' interface, so that's what I use now. It's all rather recent and I didn't release it yet.)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf