command line calculator - Page 1
Forum section: electronics / projects

author: rfclown
author_rank: Frequent Contributor
timestamp: July 09, 2022, 01:32:26 am
content: 1. I am an electrical engineer and I often want to use a calculator2. 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 calculator4. I HATE every computer calculator that I have tried because... a mouse is the WORST POSSIBLE interface device for a calculator5. I wrote a C program calculator in 2002 or so, and have used it ever sinceI'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 bclbclgcc ccalc.c -o ccalc-edit. added exe compiled on a Win7 PC-edit. replaced files with bug fix. exe in source zip file

author: rfclown
author_rank: Frequent Contributor
timestamp: July 09, 2022, 02:47:42 am
content: Quote from: evb149 on July 09, 2022, 01:49:24 amIf 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.

author: ledtester
author_rank: Super Contributor
timestamp: July 09, 2022, 02:52:06 am
content: 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 distroThis video is the best one I found which demonstrates its use:Mathematical Calculations in Linux | bc calculator in linux | programming features of bc calculatorhttps://youtu.be/B5HrLg2gu9o

author: rfclown
author_rank: Frequent Contributor
timestamp: July 09, 2022, 02:53:03 am
content: Quote from: evb149 on July 09, 2022, 01:52:46 amI 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.

author: rfclown
author_rank: Frequent Contributor
timestamp: July 09, 2022, 03:00:25 am
content: Quote from: ledtester on July 09, 2022, 02:52:06 amBack 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.

author: Alex Eisenhut
author_rank: Super Contributor
timestamp: July 09, 2022, 04:57:14 am
content: Learn APL?

author: NiHaoMike
author_rank: Super Contributor
timestamp: July 09, 2022, 05:06:29 am
content: Have you tried Speedcrunch?https://heldercorreia.bitbucket.io/speedcrunch/

author: ledtester
author_rank: Super Contributor
timestamp: July 09, 2022, 03:24:20 pm
content: Quote from: NiHaoMike on July 09, 2022, 05:06:29 amOf 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.

author: rfclown
author_rank: Frequent Contributor
timestamp: July 09, 2022, 03:58:20 pm
content: Quote from: NiHaoMike on July 09, 2022, 05:06:29 amThat 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.

author: rfclown
author_rank: Frequent Contributor
timestamp: July 09, 2022, 05:51:55 pm
content: 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.

author: SiliconWizard
author_rank: Super Contributor
timestamp: July 09, 2022, 05:59:21 pm
content: 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.htmlsource 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.)