Hacker News new | ask | show | jobs
by 5- 1693 days ago
you might want to try units(1).

https://www.gnu.org/software/units/units.html

the input language is less flexible than wolframalpha/google, but i quickly got used to it. it's nice to have something local and reliable. you can also define custom units.

i prefer using it in terse mode:

    $ units -t 0.03$/hr*1month
    21.914532 US$
    $ units -t 10TB/month Mbps
    30.421214
4 comments

qalc[1] is also quite nice if you're looking for a command line calculator; it handles units well, but has some other fancy features, and has a very lax parser which i find to be a huge plus.

    $ qalc '0.03$/hr*1month'
    error: "r" is not a valid variable/function/unit.
    (0.03 × (USD / hour)) × (1 × month) = $21.915

    $ qalc '0.03$/h*1month -> CAD'
    (0.03 × (USD / hour)) × (1 × month) ≈ CAD 27.28388011

    $ qalc '10TB/month -> Mbit/s'
    10 × (terabyte / month) ≈ 30.42056430 megabits/s

    $ qalc 'integrate(x+x^2)'
    integrate(x + (x^2)) = x^3 / 3 + x^2 / 2 + C
[1] https://qalculate.github.io/manual/qalc.html
Units advises there are 118.20896 smoots per furlong..
Wouldn’t that be properly expressed as 118 Smoots plus 5 Ears?
people still measuring in smoots smh
For calculator problems like that, I use J:

   */ 0.03 24 30
21.6

   1e6 %~ (10e12 * 8) % */ 30 24 3600
30.8642

Usually requires some massaging, but still takes seconds.

While APL dialects are very nice for this sort of thing, they generally don't understand units of measure or know about physical constants; you have to put those into them yourself. Here are some of my recent units(1) queries:

    141 pounds force 30 mm  # in joules
    1160/4
    log(3)/3/(log(2)/2)  # how much more efficient is one-hot ternary than one-hot binary?
    5V 7 μs / 7.3 A
    .0117% half avogadro mol / 1.251e9 years / (potassium+chlorine)g  # how radioactive is lite salt?
    3.27$/gallon  # in $/liter
    sqrt(2 2000 electronvolt/electronmass)
    18.8 foot pounds force # in joules
    163$/(7.9 g/cc * 1500 mm 3000 mm 3.2 mm)  # cold rolled steel price is higher than steel sold by weight
    m3/4 / 15 cfh
    2 pi sqrt(200 um / gravity)
Julia is also excellent for working with units (Units.jl, IIRC).
Unitful.jl