A unit-aware calculator

As much as I would like to avoid it, sometimes when studying physics I have had to use actual numbers. Especially in my quantum mechanics class I kept using constants like ℏ, and had to manually convert units. Typing these constants out and keeping track of conversion factors is a pain, and none of the calculator apps I used handled this use case.

Eventually I found GNU Units, an ancient CLI calculator that supports hundreds of different units and every physical constant I needed. I ended up porting it to WebAssembly and making a little UI for it. You can use it below 🙂

An example is shown by default which calculates the Newtonian gravitational force. The “To” field is optional, if you just want to calculate something without converting units. Try using any units or constants you can think of.

Open in new tab.

I also used the webview C++ library to build a Mac app for my convenience. In this case, GNU Units runs as native code (not WebAssembly) with bindings to the JS frontend. Since webview just links to WebKit on Mac, the resulting app file is tiny — just 687 KB.

You can download the Mac app (for Arm) below. Note that because of Apple’s extortion security rules, unless I pay $100 / year, you won’t be able to run the app without first running xattr -c Units.app.

The code for the UI and the WebAssembly port is ugly and bad, but it works. Since GNU Units is GPL licensed, so is my port. The Git repository is here. There’s also a Github mirror. Oh, and the calculator icon I used is from the Haiku project.

Hopefully somebody finds this as helpful as I have!

Leave a Reply

Your email address will not be published. Required fields are marked *