Tag Archives: calculator

c, calcc and calccmd: Three small calculators

Three-for-one on a Friday today, and calculators are the featured toy. The first one suffers from an unfortunate name, but seems to make up for it in its ratio of function to footprint. This is c:

2015-02-20-6m47421-c

c is an RPN calculator, and if you don’t know what that means, it might be a very confusing experience for you. c is somewhat helpful to newcomers though, since its registers are clear at every operation. Put the values you want inside, press the key for the operation, and as you can see, the result is kept in the lowermost register.

It’s not hard to figure out, and I imagine if you like RPN calculators you’ll get a kick out of such a small one — only 4.1K for the source file, and roughly twice that for the executable. It’s not often you get that much function in such a small space. Too bad its name will make it virtually unfindable. … 😦

calcc is next.

2015-02-20-6m47421-calcc

calcc is similar to c in its captive terminal approach, and has a style somewhat like bc or other calculators, with each line interpreted and calculated at once.

Its results are what set it apart; calcc saves you the step of converting your answer between bases or formats, and displays everything at once. So you won’t need a date converter or a base converter to supplement calcc. If you need a legend for what each column is, there is a text file in the source package that explains which is ASCII, which is base 32, base 64, and so forth. Very convenient.

The last one today is calccmd.

2015-02-20-6m47421-calccmd

calccmd is the only one of these three to send your calculations through as command-line arguments, and I’ll be honest and say there are times when I would prefer that approach. Sometimes I don’t want to fire up all of bc just to divide two numbers, and allow for two decimal points.

So a command-plus-flag style calculator is not unwelcome. And calccmd has enough options to keep it up to speed with what c and calcc can do, as well as quite a few other calculators. (The home page mentions that calccmd has been deprecated in favor of calccli by the same author, but I don’t see that project anywhere.)

And so, armed with those three options, feel confident as you venture forth into the world of mathematics. … :mrgreen:

tapecalc: Without the expensive paper roll

I usually use sc for tallying my home finances, but now I’m wondering if that’s the best option. Here’s tapecalc.

2015-01-19-l3-b7175-tapecalc

Ideally, tapecalc works like a traditional paper-tape calculator, like you used in your business classes in secondary school, years ago. Even the display seems to mimic the paper roll effect.

For every function there’s a value, and the line can be switched to show the operation. The topmost line shows a balance, and you can tack on comments to remind yourself when you last paid for your vuvuzela lessons. 😯

In another manner though, tapecalc works almost exactly like a check register or a simple bookkeeping ledger, meaning this might be preferable to a spreadsheet for home accounting or simple accounts and payments. Since you have a clean view of what your balance is at any given moment, you’re unlikely to run afoul of your bank manager over things like misplaced decimal points. πŸ™„

tapecalc can save “tapes” as plain text files, and read them back as source files or as annexations. You can save out your “tape,” add on regular “tapes,” and generally edit or juggle to your heart’s desire. And tapecalc is not limited to adding and subtracting; there are provisions for multiplying and dividing, as well as more complicated mathematical adventures.

I like tapecalc — a lot. I expect this will take over from sc … as soon as I get tapecalc to run in Arch. I only found tapecalc in Debian, although I don’t believe it will take much to build it elsewhere.

For all the points listed earlier this week, and for a unique take on the traditional console calculator, I’m willing to pass out a third gold star this week: ⭐ Three in a week! Another precedent broken! :mrgreen:

One final point for thought: The source file and home page call this “add,” but it appears in Debian as “tapecalc.” As best I can tell from my unskilled perusal, the Debian patch just converts the name to tapecalc. On the home page the author explains why. *BSD users may have access to this as “add.”

bpm-tools: Music and … stuff

I think I might have mentioned in the past that I have an amazing, amazing lack of musical ability. I count myself lucky in some other departments, but talent with music is not one of them.

So I’m going to take it on faith that when bpm-tools tells me there are 94.196 beats per minute in Revolution Void‘s “Invisible Walls,” it’s telling the truth.

2014-12-08-6m47421-bpm-tools

Because to be honest, I’d be at a real loss to prove it wrong. 😦

I don’t have any real reason to doubt bpm-tools, even if the home page is a little vague on the exact formulas used to analyze a particular track. I’m sure if you dip into the source code, all will be revealed.

Of course, even knowing how it goes about its calculations wouldn’t do me much good, since tempo analysis is probably something that … well, requires knowledge about … music and … stuff. Which I have already admitted I don’t have. :\

bpm-tools includes the bpm executable, and comes with a tagging utility so you can insert the results of the bpm executable into a file, for future reference. If you moonlight as a DJ from your Linux admin job, it might make things easier when looking for interlocking tunes.

bpm itself built perfectly for me in Arch, and I only touched up the bpm-tag script so it would access the executable in the same directory. Other than that, bpm-tools was a completely hands-free experience.

bpm-tools is in Debian for Jessie. There is a PKGBUILD in AUR that will hold your hand while you build bpm-tools, but doesn’t seem to take into account that sox is necessary to make it run. And if you want to draw on the tagging feature, you’ll need the appropriate library to support that (vorbis-tools for ogg files, just so you know).

datamash: Statistical tools for raw numerical data

I like tools that do simple things in obvious ways. I like tools that have color too, but sometimes I’m willing to forgive that, and award points on cleverness.

Here’s datamash, a GNU tool, doing something fairly straightforward.

2014-10-02-6m47421-datamash-01

Forgive my rotten formatting. I was trying to line up the sums under their appropriate columns, but I ran out of patience with it. What you should see there are two arbitrary columns of numbers, and datamash summing both on the fly.

It’s not a terribly earth-shattering function, but it does make a lot of otherwise tricky number functions accessible to flat numeric data files. So you don’t have to import into a spreadsheet to get a sum, a mean, a max, a min or whatever.

And you don’t have to rely on statistical packages like r or octave to do some simple budget analysis. πŸ˜‰

datamash also does some rather clever text formatting tricks, which might be reason enough to keep it installed. Observe:

2014-10-02-6m47421-datamash-02

So you can feed datamash a series of columns vertically, and it will run them out horizontally. Omigoshthatissocool.

datamash is in AUR and testing/unstable. I don’t know why it’s not in the standard repos for either distro, except that it may be too new. The development pages for datamash suggest it started about a year and half ago, but saw most of its activity within the past six months. Give it time.

A lot of what datamash can do — particularly the higher statistical functions — are much more than I would need on a day-to-day basis. But if you keep something like r or octave on board for regular data analysis, you might consider datamash as a lighter alternative.

ipcalc and pipcalc: More than a one-letter difference

I’m going to lump ipcalc and pipcalc together today, for reasons that are probably immensely obvious just from looking at their names. And since neither one takes up much screen space in its default form, I can squish them both into one screenshot.

2014-09-11-6m47421-ipcalc-sipcalc

And there you have it. Both programs calculate IP information given a particular address, and return extended results. As far as I can tell neither one needed actual network access to accomplish that feat, so I believe they could be of use on an offline machine too.

And it’s likewise obvious from looking at that screenshot, that there are some intricacies in the way both programs display their results. ipcalc is considerably more detailed (and colorful πŸ˜‰ ), and pipcalc is considerably more succinct.

Networking always has been, and probably always will be, a weak point for me, so how either of these tools — or sipcalc or prips, for that matter — are of practical use is a bit vague.

I will leave it to those of you with more experience and more need to tell me which of these four is the most useful. Me being me, I’m most likely to just pick the one with the most color. πŸ™„

e: Like a diamond bullet

I will apologize first, for the long lapse in communication. The end-of-season workload in real life took over late last week, and very foolishly I did not make preparations for posts during that time. I should have; I knew it was coming, but I acted all surprised when I suddenly had no time for the things I enjoy — like picking around at software.

But it should all be okay now. At least I have a better handle on real life responsibilities. :\

e is the topic of choice today, and what I’d really like to point out about e is this:

-rwxr-xr-x 1 kmandla users 6.9K Jul 11  2001 e
-rw-r--r-- 1 kmandla users 4.0K Jul 11  2001 e.c

Yup, the e binary is a meager 6.9K in size, and the source code would fit in an Atari 2600 game cartridge. Technically. Sort of. Maybe. πŸ™„

That’s impressive for a one-shot command-line expression evaluator — or calculator, as some like to call it. Hand just about any expression to e and it will click and sputter briefly before throwing out an answer.

And not just simple math either. All these things are legitimate e commands.

kmandla@6m47421: ~/downloads/e-0.02718$ ./e 128!
385620482362580407155136441409207201389253268216532306772217329749547863719106679162867854358801401227806481764781487371873131030193755466921909305056470590141451680483549478144909375453156147105979268404276583464960

kmandla@6m47421: ~/downloads/e-0.02718$ ./e 1/2*1/3*1/4*1/5
0.00833333333333333

kmandla@6m47421: ~/downloads/e-0.02718$ for i in {0..90..15} ; do ./e sin[${i}] ; done
0
0.650287840157117
-0.988031624092862
0.850903524534118
-0.304810621102217
-0.38778163540943
0.893996663600558

That’s impressive for a 7K binary with no, repeat no dependencies. To quote from the home page, “It doesn’t need bison or anything else other than a C compiler. In fact it is a recursive-descent parser with one character look-ahead.”

For its size and its potential, e should be an addition to just about any system. No more mucking around with bc while trying to balance your checkbook. e can solve it all in a fraction of the time, and take up no more space than a postage stamp.

And if you enjoy math logic, the home page has an interesting (and convincing, from my uneducated perspective) treatise on why zero is not a number and why just a plus sign — “+” — should evaluate to zero. I’m a believer now.

By the way, I owe a small note of thanks to NiceGuyJoe on reddit who sent me a message months ago linking to e, and it has just come up in the rotation. A good lead, all the same. πŸ™‚

Now, let’s talk about that one-character program name. … 😑

factor: Simple tools are fun

After more than a year and a half of tinkering with random console programs, I know enough to look forward to fun stuff out of coreutils. Here’s factor, which I admit has almost no explicit function beyond showing the prime factorization of a number.

kmandla@6m47421: ~$ factor 120
120: 2 2 2 3 5

Which is absolutely correct, of course: 2x3x4x5 does in fact equal 120, and factor is nice enough to group similar factors for readability.

But that’s all it does. So what’s the big deal, K.Mandla?

Well, aside from fulfilling my desire to see simple, straightforward, light but functional software, factor has potential. My only real concession to factor is that I’d prefer I had a count of how many of each factor there were, rather than just a string of factors. That would mean factor 65536 would appear as

65336:
16x2

rather than just a string of 16 number 2s. Call me picky.

First let’s lose the colon-plus-space arrangement, and kick in a tab character instead, for reasons that will be clear in a moment. sed can help with that.

factor 720 | sed -e 's/: /\t/g'

I’d prefer a tab character there only because cut likes tab characters as delimiters.

factor 720 | sed -e 's/: /\t/g' | cut -f2

Now we just need to break off each number where a space appears, and we can call in some heavyweights. sed again, just for kicks.

factor 720 | sed -e 's/: /\t/g' | cut -f2 | sed -e 's/ /\n/g'

Now we go medieval. Remember uniq? Watch this:

factor 720 | sed -e 's/: /\t/g' | cut -f2 | sed -e 's/ /\n/g' | uniq -c

Four twos, two threes and a five. Yup, that’s right. That’s 720. uniq counted the lines and gave a total. Too much whitespace at the front though.

factor 720 | sed -e 's/: /\t/g' | cut -f2 | sed -e 's/ /\n/g' | uniq -c | sed -e 's/^[ ]*//g'

And it would be nice if there was just a multiplier mark between the count and the factor.

kmandla@6m47421: ~$ factor 720 | sed -e 's/: /\t/g' | cut -f2 | sed -e 's/ /\n/g' | uniq -c | sed -e 's/^[ ]*//g' | sed -e 's/ /x/g'
4x2
2x3
1x5

Close enough for government work. From there we would only need to prefix the output with the number, like I showed above. If you stick this in a loop, it becomes even more interesting. Try

for i in {2..99} ; do echo $i':' ; factor $i | sed -e 's/: /\t/g' | cut -f2 | sed -e 's/ /\n/g' | uniq -c | sed -e 's/^[ ]*//g' | sed -e 's/ /x/g' ; echo ; done

for more complete (replete?) results.

What’s the point in all this? Not much of one, that I can see. This wasn’t meant to be some sort of lesson on sed and uniq; suffice to say I have plans for that particular loop that are … beyond the focus of this blog. Feel free to adjust it to your own nefarious plans. πŸ˜‰

wcalc: A calculator with a conventional appeal

There is a mighty swirl of calculators for the console, and wcalc is caught up in it.

2014-06-21-6m47421-wcalc

Reaching back, we can draw on qalc, orpie, ised, concalc, calc, and even bc. Does the world need another cli-based calculator?

You can decide that. I will give wcalc a nudge for keeping a more conventional and less eccentric approach. Its help screen is pleasantly brief (although more detail is possible), and it behaves a little more like a forgiving pocket calculator than its peers.

Don’t take that to mean wcalc is somehow less powerful than the ones I listed up there. I have no reason to believe wcalc isn’t a contender in the scientific calculator bracket.

wcalc just seems more … approachable. For example, one nice touch in wcalc is the reservation of the “a” variable as the answer last supplied. In other words, your last result is pushed straight into the variable “a,” and you can use that immediately in your next calculation. Nice touch.

You can also supply data in hex, binary, octal or scientific notation, and comment out lines much in the same way as some programming languages.

I like wcalc, and I believe the next time I’m in the market for a console calculator, I might reach for it first. I’ll let you know when the moment arrives. πŸ˜‰

teapot: Said the hatter with a sigh, ‘It’s always tea-time. …’

This will also be a shortened post, since 99 percent of what I could tell about teapot was committed to the great cesspool of knowledge known as The Internet years ago.

2014-05-20-jk7h5f1-teapot

teapot is a spreadsheet. teapot manages data in three dimensions. teapot is great for math, but might not be ideal for your basic home budget. teapot is a little unusual at first, but makes a lot of sense once you get used to it.

If you want to get your hands dirty with teapot, I’d recommend first looking at that link above, then starting into the documentation. By the time you work through that, you should have the majority of teapot’s mainstream functions completely mastered.

So you might wonder … if teapot is so great, why do I still use sc on a daily basis? Easy answer: Most of my spreadsheets are extremely simple things, like budgets or calorie counts for recipes. Put simply, teapot would be overkill. 😐

It’s all about using the right tool for the right job. … πŸ˜‰

slsc: Out of a sense of duty

Time for a sad story. I’m going to list slsc here today, even though in my entire career as a Linux enthusiast, I don’t recall ever having seen it work, on any distro, not even once. 😦

My meager understanding of slsc lumps it into the category of “slang rewrite of sc,” which would make it a basic text-only spreadsheet. It’s on my list of console applications because it’s always possible that some obscure distro somewhere carries it in a working form. I can hope, anyway.

Its obsolesence is discouraging, mostly because slsc, as I understand it, stands among some cornerstone software for the console. Programs like slrn, mutt, jed and others all depend on the slang library, and slsc was at the vanguard of that movement.

Unfortunately, as best I can tell, it needs the 1.2.2 version of slang (I’m guessing that because there’s a dead link to it in the slsc folder, above), which went out of fashion eons ago.

It must have worked fairly recently though. Back in 2006, slsc was part of Ubuntu, if the Dapper man page is any indicator. Now it’s not in Arch, or AUR, or any active version of Debian that I can see. 😦

Out of a sense of duty I tried to build slsc against the newest slang, and it wasn’t happy with that. I didn’t have much more luck building slang 1.2.2. How times have changed.

Console text-only spreadsheets are a dying breed. oleo and slsc have succumbed to the weight of the ages, and as far as I know, only sc and the emacs-integrated ses (and teapot!) still exist. Unless there are some surprises for me in the T-Z sections. 😦

Of course the irony of that is, the first “killer app” and the program that put home computers on the map was a phosphorescent green text-only spreadsheet. Those were the days. … πŸ˜‰