Author Topic: favorite CLI calculator?  (Read 1476 times)

0 Members and 1 Guest are viewing this topic.

Offline 50ShadesOfDirtTopic starter

  • Regular Contributor
  • *
  • Posts: 110
  • Country: us
favorite CLI calculator?
« on: June 16, 2023, 10:25:12 pm »
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).
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14448
  • Country: fr
Re: favorite CLI calculator?
« Reply #1 on: June 16, 2023, 10:31:04 pm »
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.
 

Offline linux-works

  • Super Contributor
  • ***
  • Posts: 1997
  • Country: us
    • netstuff
Re: favorite CLI calculator?
« Reply #2 on: June 16, 2023, 10:55:42 pm »
$ echo "3.14 * 2" | bc
6.28

works fine.  you need more than that? ;)

Offline 50ShadesOfDirtTopic starter

  • Regular Contributor
  • *
  • Posts: 110
  • Country: us
Re: favorite CLI calculator?
« Reply #3 on: June 16, 2023, 11:06:50 pm »
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!
 

Online Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6244
  • Country: fi
    • My home page and email address
Re: favorite CLI calculator?
« Reply #4 on: June 16, 2023, 11:26:34 pm »
I use a quick gawk script (~/bin/c with ~/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 mostly maxima for anything more complicated like solving equations.

Code: [Select]
#!/bin/sh
export LANG=C LC_ALL=C
exec 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 }'
 

Offline linux-works

  • Super Contributor
  • ***
  • Posts: 1997
  • Country: us
    • netstuff
Re: favorite CLI calculator?
« Reply #5 on: June 17, 2023, 05:31:34 pm »
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: [Select]
bc 1.07.1
Copyright 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/3
0
scale=2
1/3
.33

have 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.

Offline golden_labels

  • Super Contributor
  • ***
  • Posts: 1208
  • Country: pl
Re: favorite CLI calculator?
« Reply #6 on: June 17, 2023, 09:14:57 pm »
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.
« Last Edit: June 17, 2023, 09:26:54 pm by golden_labels »
People imagine AI as T1000. What we got so far is glorified T9.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf