favorite CLI calculator? - Page 1
Forum section: electronics / general

author: 50ShadesOfDirt
author_rank: Regular Contributor
timestamp: June 16, 2023, 10:25:12 pm
content: I've been exploring new (and old) calculators that I can drive from CLI ... no particular reasons other than to keep up with current technology.I have no heavy calculation requirements either, other than as I almost always have a cmd window open, I want to throw a calculation at it ... something quick that I know how to do, or something I've just read about, and want to do that calc myself.Under Win (new calcs), these 3 have varying usefulness for me:- Qalculate (has gui/cli)- Wolfram Engine (can get community edition free from their website)- Fend (just now checking it out)The Qalculate is yet another GUI calc for win, and usually what I use on the desktop, but it also has a cli which I'm exploring; I use Chocolatey to install/update it, but it's also on github.Wolfram's I discovered on RPi (part of the official OS), and found also that I can ask for it from their website (for Win). Can't afford a GUI version of it (mathematica), but the free cli version lets me stick my toes into Wolfram Language a bit. Lots to learn here ...Fend is yet another purely cli calculator off of github ... I usually discover things on Chocolatey, and then just go to the source on github and learn more about the app.Under old (emulators on Win) ... normally, old things would be in the vintage subforum, but I'm using modern emulators, so discussing it here as well:- Cemu (TI83/84)- WabbitEMU (also TI)- Free42 (HP)On these emulators, I'm just trying to relearn how to use these "old" calculators for current efforts.What does everyone else know about and/or use, old or new? Pointers about your favorite would help me discover and learn more about these things ... perhaps even get smarter than my kids ... maybe.I threw this crusty "baseball" word problem at them (found on a job board article, apparently part of the "Cognitive Reflection Test"), trying to get my kids to reason through it OR use the cli calculator for the word problem (algebraicly):"A bat and a ball cost $1.10 in total. The bat costs $1.00 more than the ball. How much does the ball cost?"Head-scratching ensued ...Bonus points if you can throw word problems at CLI (and no ChatGPT, as that is online only, AFAIK).

author: SiliconWizard
author_rank: Super Contributor
timestamp: June 16, 2023, 10:31:04 pm
content: I have used calc for many years (before writing my own, that I use now):https://sourceforge.net/projects/calc/Packages available on many Linux distros, otherwise not hard to build on those.Although it can also be built on Windows (I did), I don't think there are official binaries out there.

author: linux-works
author_rank: Super Contributor
timestamp: June 16, 2023, 10:55:42 pm
content: $ echo "3.14 * 2" | bc6.28works fine. you need more than that?

author: 50ShadesOfDirt
author_rank: Regular Contributor
timestamp: June 16, 2023, 11:06:50 pm
content: BC is linux cli calc, and thanks to your pointer, I did find some GNU "compiled for win" versions of it out there ... adding that to my list.Now exploring if the win versions are as feature-complete as the linux version ... digging into that.It's not so much what *I* need, it's what's out there, and what I can do with it ... it might become another tool in the toolbox.Perhaps I can add linux cli tools to a very small linux distro in a vm (DSL, or other), and have that at hand ... might open up the linux side ...Thanks!

author: Nominal Animal
author_rank: Super Contributor
timestamp: June 16, 2023, 11:26:34 pm
content: I use a quick gawk script (~/bin/cwith~/bin/in my path) to handle trivial stuff like"c 13860/19601"to get"0.707106780266"(and to use my preference for rounding, halfway away from zero), and mostlymaximafor anything more complicated like solving equations.Code:#!/bin/shexport LANG=C LC_ALL=Cexec gawk 'function choose(n, k) { choose_r = 1; for (choose_i = 1; choose_i <= k; choose_i++) choose_r *= (n - choose_i + 1) / choose_i; return choose_r }function asin(arg) { return atan2(arg, sqrt(1.0 - arg*arg)) }function acos(arg) { return atan2(sqrt(1.0 - arg*arg), arg) }function atan(arg) { return atan2(arg, 1.0) }function tan(arg) { return sin(arg)/cos(arg) }function abs(arg) { if (arg < 0.0) return -arg; if (arg > 0.0) return arg; return 0 }function fact(n) { fact_r = 1; for (fact_i = 1; fact_i <= n; fact_i++) fact_r *= fact_i; return fact_r }function log10(x) { return log(x)/log(10) }function log2(x) { return log(x)/log(2) }function floor(x) { return (x < 0 && int(x) > x) ? int(x) - 1 : int(x) }function ceil(x) { return (x > 0 && int(x) < x) ? int(x) + 1 : int(x) }function round(x) { return (x < 0) ? int(x - 0.5) : int(x + 0.5) }function bin2int(s) { _bin2int_v = 0; gsub(/^0+/, "", s); gsub(/[^01]/, "", s); for (_bin2int_i = 1; _bin2int_i <= length(s); _bin2int_i++) { _bin2int_v *= 2; if (substr(s, _bin2int_i, 1) == 1) _bin2int_v++ } return _bin2int_v }BEGIN { Pi = PI = pi = 3.14159265358979323846 ; deg = pi/180 ; s = sprintf("%.12f", ('"$*"')); sub(/00*$/, "", s); sub(/\.$/, "", s); printf "%s\n", s }'

author: linux-works
author_rank: Super Contributor
timestamp: June 17, 2023, 05:31:34 pm
content: I'll either run 'bc' (or dc if that's the only one installed) and sit there. note, you have to set precision (bugs me).Code:bc 1.07.1Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc.This is free software with ABSOLUTELY NO WARRANTY.For details type `warranty'.1/30scale=21/3.33have to set 'scale' to be of any use. just remember that. I think there may be some dot init file you can set that to. maybe.

author: golden_labels
author_rank: Super Contributor
timestamp: June 17, 2023, 09:14:57 pm
content: Python?The downside is operating in a mixed mode (floating point, native integer and bigint) regime all the time. Other software will usually not care about numerical stability unless advertised as such, so this is not a huge disadvantage. But still may have unexpected consequences.The advantage is being able to use external, well tested libraries for additional functionality.