2025-03-13 Calculators and spreadsheets ======================================= I stumbled upon a discussion about the Gnome Calculator. Apparently it stopped working for some people because a bank blocked it from retrieving the exchange rates it needs to allow users to do currency conversions. I get it. It's a feature, it needs data that's up to date, so you need to fetch it. The default is to do this once a week, I hear. Based on currency-provider.vala, the currency providers are the International Monetary Fund (IMF) and the European Central Bank. So that leads me to another question: What do you use to do calculations you can't do in your head? I mostly do it in Emacs using M-x calc. It uses the reverse-polish notation (RPN) I am used to from my old calculators before there where smartphones. For a while I used bc but the precision was weird. Then I tried dc but it was weird, too. Now I have Super+C bound to orpie running in a terminal. Perhaps I should bind that key to run emacsclient and eval (calc). 😂 From the replies, I found a large number of people reporting that they used the interpreters of their favourite programming languages. I didn't know that this was so wide-spread. People named Python, Ruby, Fennel, Scheme. Python: Python 3.11.2 (main, Nov 30 2024, 21:22:50) [GCC 12.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> 1+2+3 6 Ruby: irb(main):001:0> 1+2+3 => 6 Fennel: Welcome to fennel! >> (+ 1 2 3) 6 Chicken Scheme: CHICKEN (c) 2008-2021, The CHICKEN Team (c) 2000-2007, Felix L. Winkelmann Version 5.3.0 (rev e31bbee5) linux-unix-gnu-x86-64 [ 64bit dload ptables ] Type ,? for help. #;1> (+ 1 2 3) 6 @HaraldKi@nrw.social shared that they use a shell, but not just any shell: tclsh with the expr built-in command. > Tclsh uses just double math, afair, and understands plain and simple > everyday expressions you basically learned in primary school. Plus > scientific notation like 2.7e22 . Plus a chunk of log, sin, cos, tan > if really needed. So no brain tweaks needed. The only thing to keep > in mind: add .0 to most numbers to not accidentally get 3/4 -> 0. The key is have a function in your shell that gets transformed into a Tcl command that is piped to tclsh. In my case, using fish, use funced calc --save and use the following: function calc echo "puts [expr {$args}]" | tclsh end At the shell prompt: > calc 1+2+3 6 > calc 4/3 1 > calc 4/3.0 1.3333333333333333 What about the other options? I think the key is that they have to startup fast and be ready to type. bc certainly qualifies. Just remember to set the scale! Or use the --mathlib option. 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+2+3 6 4/3 1 scale=3 4/3 1.333 dc has reverse-polish notation (RPN) but is very terse. Tokens are separated by spaces or newlines. Thus, the Enter key doesn't print a result. You need to use the p command. Again, the default is integer math. Use the k command to switch scale. 1 2 3 + + p 6 4 3 / p 1 3 k 4 3 / p 1.333 A weird part is that you need to enter negative numbers using the underscore (_3 for -3). By contrast, my favourite calculator in the terminal right now is orpie. You get reverse-polish notation and immediate feedback. Orpie v1.6.1 -- swap drop dup view | 25: --------------------------------------| 24: Calculator Modes: | 23: angle: RAD base: DEC complex: REC | 22: | 21: Common Operations: | 20: enter : | 19: drop : \ | 18: swap : | 17: backspace: \177 | 16: add : + | 15: subtract : - | 14: multiply : * | 13: divide : / | 12: y^x : ^ | 11: negation : n | 10: Miscellaneous: | 9: scientific notation : | 8: abbreviation entry mode : ' | 7: stack browsing mode : | 6: refresh display : C-L | 5: quit : Q | 4: | 3: | 2: 6 | 1: 1.33333333333333 -------------------------------------------------------------------------------- Emacs comes with M-x quick-calc which simply asks for an expression and prints the result: Result: 1 + 2 + 3 => 6 (16#6, 8#6, 2#110, "^F") Then there's M-x calculator which comes with its own mode. You can use o h to switch output to hex, for example. So adding up 1 + 2 + 3 + 4 results in 10, or A in hex. Calc==H> A And finally there is M-x calc. Check out the short tutorials by Andrew Hyatt, if you're interested in learning more. As I said above, this is my default solution. 1 RET 2 RET 3 RET + + and there we go. Plus a trail over on the right in case you're confused. ---------------------- Emacs Calculator Mode ---------------------- |----- Emacs Calculator Trail ----- 1: 6 | 1 . | 2 | 3 | + 5 | +>6 | | -UUU:%*--F1 Calc: 12 Deg All L2 (Calculator) ---------------|-UUU:%*--F1 *Calc Trail* All L5 Copying the result runs into a tiny problem, for me: The stack depth is copied along with it! So if you copy the above result (6), what you actually get is 1: 6. Which is never what I want to paste elsewhere. Never. @kickingvegas@sfba.social suggested casual-calc, which is part of "a project to re-imagine the primary user interface for Emacs using keyboard-driven menus". @m@helvede.net suggested qcalc which also offers “currency conversion”: > The exchange rates can be updated manually using File → Update > Exchange Rates, or automatically at specific intervals (by default > once every week, but this can be changed in the preferences dialog), > when needed (when currencies are converted). Apparently it gets the exchange rates from the European Central Bank and Coinbase App APIs. Another option is spreadsheets, of course. @neauoire@merveilles.town mentioned nebu. I don't have a Varvara system up and running, however. There is sc, of course. If you don't want to hit = for every number you enter, use -n for "quick numeric entry". I'm not sure how I can quickly select the range for something like @sum(A0:A2) but it certainly seems possible to use sc for interesting stuff. B2 (10 2 0) [B0/B1] A B C D E F G 0 1.00 4.00 1 2.00 3.00 2 3.00 1.33 3 6.00 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Visidata (vd) also looks interesting. Sadly I have no idea how to do anything. 😂 File Edit View Column Row Data Plot System Help Ctrl+H for help menu directory │ filename ║ ext │ size #│ modtime 1› .| BUTTON1_RELEASED no-op 0 files •0 Of course, Emacs also comes with a spreadsheet. Visit an empty file ending with .ses. Enter a number. To add a new row, use down then create a new cell using TAB and enter a second number. When you need a formula, use (apply ses+ (ses-range A1 A3)), for example. File Edit Options Buffers Tools SES Help A B C D 1 2 3 6 #Calculators #Spreadsheets #Software