Published: Updated:

Digits is an android app designed to make engineering and scientific calculations easier. It was born out of my own need to perform calculations with units of different magnitude. Users may upgrade to a “pro” mode if they would like access to a larger variety of skins. Parsing is done over a unicode string, so the user may copy/paste expressions if they wish.

Users can convert between any two units of the same dimension. The app shows users if they made a mistake. Here, two unlike units are subtracted. The correct unit is calculated internally, then converted into the best unit to display to the user. Tapping and holding will reveal additional functions. There are a variety of skins to choose from. This picture shows a couple composited together. Significant figures are included in the calculations.

Technical details

The app is written entirely in Kotlin. Currently, the BigDecimal library is used for the numerical calculations. Unit calculations are performed in terms of SI base units. Significant figure calculations are performed alongside numerical ones.

The app is divided into four components.

  • UI- This accepts controls from the user. It uses the parsing component to calculate the result and the humanization layer to display it.
  • Parsing- This reads the user input and evaluates the expression and any errors. It uses the calculation component.
  • Calculation- This performs the value, unit and sigfig calculations.
  • Humanization- This heuristically formats internal values and units into something the user prefers to see.

Since all calculations are performed in terms of SI base units, they must be humanized before being displayed to the user. Humanization of the units is performed by running Dijkstra’s algorithim over a graph which starts at a unitless quantity and each edge adds a derived unit (like seconds, joules, or amps). For example, if the result of a calculation has the units m⋅s⁻², the unit m/s² is chosen after exploring m -> ms⁻¹ -> ms⁻² and rendering the result as m/s². If the result of a calculation has the units kg⋅m²⋅s⁻¹, Js is chosen because it could be constructed by using a derived unit twice. The search is directed by minimizing by the difference in SI base units. This keeps a unit like s⁴ from being searched before Js. These results are cached so performance with unnaturally large units, like s⁶⁰, is fine.

Unit tests are used to validate the parsing, calculation, and humanization components.