GNU Units
this page seriously undersells the versatility and utility of the units program
how long will my laptop take to charge at its current rate of charging?
how long will a 2000mAh 18650 cell take to discharge at 2.5 watts, using a nominal voltage of 3.7 volts?You have: (22.8 Wh - 16.8 Wh)/7.4W You want: time 48 min + 38.918919 sec
what energy density is that, so i can compare it to the volume needed for other forms of energy storage?You have: 3.7 V 2 amp hour / 2.5 watt You want: time 2 hr + 57 min + 36 sec
what's the specific energy of stoichiometrically mixed oxyhydrogen fuel?You have: 3.7 V 2 amp hour / circlearea(half 18 mm) 65 mm You want: MJ/ℓ * 1.6105936 / 0.62088909
okay but how much volume? say at atmospheric pressure?You have: 44000 J/mol / ((2 hydrogen + oxygen)g/mol) You want: MJ/kg * 2.4423711 / 0.40943818
so that's how much energy density?You have: 3 mol gasconstant tempC(20) / 1 atm You want: l * 72.165351 / 0.013857066
(i may be off by a factor of 2 here)You have: 44kJ/_ You want: J/l * 609.71089 / 0.0016401216how much energy can this capacitor hold?
how much energy density is that?You have: half (10V)**2 47 uF You want: mJ * 2.35 / 0.42553191
how thick of a cable do i need to support me in a lightweight fabric-sling chair (or, from a different point of view, to pose a risk of accidental strangulation)? suppose its tensile strength is 2.7 gigapascalsYou have: half (10V)**2 47 μF / 15mm circlearea(3mm) You want: J/ℓ * 5.5409499 / 0.18047447
note that this is the radius of the cable, not its diameter!You have: 120kg gravity / 2.7 GPa You want: mm2 * 0.43585111 / 2.2943615 You have: _ You want: circlearea 0.00037247244 m You have: _ You want: mm * 0.37247244 / 2.6847624the datasheet says this 400×240 display uses 175 μW if all the pixels flip once per second and 60 μW for a static display. how much energy is that per pixel flip?
if i overclock it to 60 fps how much power will it use?You have: (175 uW - 50 uW) / 400 240 1 Hz You want: nJ * 1.3020833 / 0.768
and how many pixels is its diagonal?You have: 60 Hz 400 240 1.3nJ You want: μW * 7488 / 0.00013354701
what is the visual angle subtended by the sun as seen from earth?You have: 400**2+240**2 You want: Definition: 217600 You have: _**.5 You want: Definition: 466.47615
okay, how does that compare to the moon?You have: 2 sunradius/sundist You want: milliradians * 9.3049358 / 0.10746984 You have: _ You want: dms 31 arcmin + 59.280781 arcsec
on average the moon looks a little smaller, which is why annular eclipses are so common, but we can also calculate that total eclipses are possible because sometimes the moon looks biggerYou have: moonradius 2 / moondist You want: Definition: 0.0090426639
what percentage of this copper sulfate is actual copper?You have: moonradius 2 / moondist_min You want: Definition: 0.0097530864
how fast can i write to this slc flash chip without wearing it out in 53 years, assuming perfect wear leveling and no write amplification?You have: copper / (copper + (sulfur + 4 oxygen)) You want: % * 39.813395 / 0.025117175
how much fuel will this truck need to get across the country?You have: 100 thousand 128 MiB/53 years You want: bytes/second * 8024.8943 / 0.00012461223
how much is that per kilogram of lettuce or sodium lauryl sulfate or whatever?You have: 4000 km / (6.5 miles/gallon) You want: l * 1447.4744 / 0.00069085852
okay, but how much energy is 52 mℓ of diesel per kg of lettuce?You have: _/28 tonnes You want: ml/kg * 51.695513 / 0.019344039
how much data can i transfer overnight during unmetered hours on a 2400-baud modem?You have: _ 38.6 kJ/l You want: kJ/kg * 1.9954468 / 0.5011409
how much power does the earth receive from the sun, assuming a solar constant of 1400 W/m²?You have: 8 hours 2400 bps You want: MB * 8.64 / 0.11574074
what would the equilibrium temperature of an object be if it were illuminated at that brightness and had a flat emission spectrum?You have: 1400 W/m**2 * circlearea(earthradius) You want: petawatts * 178.52313 / 0.0056015152
how about here in buenos aires at the winter solstice? first, what angle is the sun at anyway? we're at 34°36’ south, and the sun's latitude at the solstice is 23°26’You have: (1400 W/m**2 / stefanboltzmann)**(1/4) You want: tempC 123.24583
so that reduces the peak insolation to how much? here underneath the atmosphere we only get 1kW/m²You have: 34° + 36' + 23° + 26' You want: dms 58 deg + 2 arcmin
and that would be what temperature in equilibrium?You have: cos(_) 1000 W/m^2 You want: W/m^2 * 529.4258 / 0.0018888388
(integrating the sun's angle over the course of the day as the earth rotates is sadly beyond its capacities)You have: (_/stefanboltzmann)**(1/4) You want: tempC 37.698189how much money could a sensible heat storage reservoir of 15 kg of water save me over 16 years? say power rates go down to only 2.5¢/kWh because of solar
what's the surface area of a 300mm × 400mm × 150mm backpack? like how much cloth?You have: 1500 kcal/day * 16 years * 2.5 cents/kWh You want: Definition: 254.69556 US$
okay but in cm²You have: 2 (300mm 400mm + 400mm 150mm + 150mm 300mm) You want: Definition: 0.45 m^2
what's the electrical impedance of a 1000 μF cap at an audio highpass frequency of 20Hz?You have: _ You want: cm2 * 4500 / 0.00022222222
what's the time constant of 100 pF (roughly the smallest capacitance you can get in a macroscopic circuit with any degree of precision) and 1 MΩ?You have: 1/(2 pi 20 Hz 1000 uF) You want: ohms * 7.9577472 / 0.12566371
okay. so how long will an 0.1μF cap take to discharge through a 100kΩ resistor from 5 volts down to a 1.3 volt threshold?You have: 100 pF 1 megohm You want: ms * 0.1 / 10
how many bits of precision does a linear adc need to be able to measure a difference of 1.8 millivolts if 1.5 volts is full-scale?You have: ln(5V/1.3V) .1 uF 100kilohm You want: ms * 13.470736 / 0.074234991
if this oxygen absorber contains 7 grams of iron which oxidizes to Fe₂O₃, how much air can it remove all the oxygen from? air is 21% oxygen by volume (and roughly by mass) and weighs 1.2 grams per literYou have: log(1.8mV/1.5V)/log(2) You want: Definition: -9.7027499
i've lost 7 kg over the last two months; how much of a caloric deficit does that represent in my diet?You have: 3 oxygen / 2 iron * 7 g You want: g * 3.0082138 / 0.33242318 You have: _/21%/(1.2g/ℓ) You want: ℓ * 11.937356 / 0.083770641
if you were to spread the moon evenly over russia, how deep would it be?You have: 7 kg 3500kcal/pound / 2 months You want: kcal/day * 887.30034 / 0.0011270141
how big is nigeria compared to massachusetts?You have: spherevol(moonradius) / area_russia You want: Definition: 1286134.4 m
how many ounces of platinum is a ton of oil worth at 40 dollars per megawatt hour?You have: area_nigeria/area_massachusetts You want: Definition: 33.793093
or in grams?You have: tonoil 40 dollars/MWh You want: platinumounce * 0.58368883 / 1.7132416You have: tonoil 40 dollars/MWh / platinumprice You want: g * 18.154752 / 0.055081997I had a lot of fun working with the maintainers of this utility to better support Gaussian units[1]. This is usually done (incorrectly) by multiplying, say, some number of SI coulombs by a dimensionless constant (actually 2_997_924_580) to produce some number of statcoulombs that represents the same charge. It's very subtle, though, that statcoulombs and coulombs have different dimensions (which is the point of Gaussian units) despite representing the same physical quantity[2], so the conversion is much more involved. I learned a lot about the nature of units and software development working with them.
[1]: https://en.wikipedia.org/wiki/Gaussian_units
[2]: A consequence of this is that electromagnetic equations formulated in terms of Gaussian units have goofy things like sqrt(grams) as "base" units. That was the tricky part to handle.
IIRC, GNU Units was once the center of a small controversy. Google (still, AFAIK) offers unit conversion as a part of their search box; you can type a unit conversion into Google and get a conversion done. Some people noted this, wondered about what the backend might be, and typed some stuff in which was known to trigger a then-present bug in GNU Units. And wouldn’t you know it, Google showed the same bug. This was all well and good, since GNU Units uses GPL, not the AGPL (which did not even exist at the time). But then some time later, Google fixed the bug; the unit conversion could no longer be triggered to exhibit the bug. But no fix for GNU Units was forthcoming from Google. At the time, this was surprising and cause for some hullabaloo, since Google was still ostensibly in their “Don’t be evil” stage.
(Disclaimer: I only heard about all of this via the rumor mill; some details may be wrong or omitted.)
This is a great program and I use it almost every day. A+
For my local units file, I've also defined a “floppyMB” for retro computing purposes. The old “1.2 MB”, “1.44 MB”, “2.88 MB” measures were based on the idea that “1 MB = 1000 KiB” (seriously). The “1.44 MB” floppies would be measured as either 1.47 MB or 1.41 MiB in more conventional units.
echo "floppyMB 1000 KiB" >> ~/.units units "1.44 floppyMB" MiBThis tool is underrated. Failing to deal with units conversion already crashed a Mars probe: https://www.latimes.com/archives/la-xpm-1999-oct-01-mn-17288...
I wonder if the recent problem with the voyager was due to something like this, for example, 2 arcminutes or 2*pi radians being mistaken for 2 degrees.
Only tangential to this but somebody might find it usefull. I’m doing lots of calculations in Python involving various units. I’m using a similar library called Pint. https://github.com/hgrecco/pint
My business is thermodynamics of power plants. Professionals in the industry tend to use convenient units like C, bars, kJ/kg and so on. But the formulas usualy need basic SI units. Using this library not only streamlines the conversion process but also keeps track of the unit itself. So instead of variable turbine_output_gj and turbine_output_mw I can have just turbine_output which is convenient.
It is hard to put a value on that but I believe it has already spared me many trivial mistakes that I had to explain to my clients.
I personally use Qalculate (https://qalculate.github.io/), specifically their CLI version for this purpose. I'm not sure how well it compares to GNU Units, but it works well enough for my needs; and it's fairly simple due to the English syntax.
Units of measure are, of course, the aboriginal type system for pre-software hand calculation.. carrying units along to make sure you do not add apples to oranges { unless you know how to convert "apples" to "oranges" for some adapted metaphorical fruits.. e.g. orange section/segment/slices :-) }.
Nim [1] has sufficient compile-time strength that units can be integrated with the static type system: https://github.com/SciNim/Unchained
I haven’t looked at the code for this but somehow I think the conversion problem is very similar to a graph search. If you build a graph in which the vertices are the units and the edges are compatible convert scales, you can use this graph with say, BFS to find the right traversal path. Multiplying the scales would get you the result converting from a unit to another. Or, dividing would give you the reversed conversion. I used to think we could use a hash table for this kind of stuff. It is faster of course but you need to account for all sort of conversion, even the crazy ones like Lightyear to feet’s, for instant. With the graph, I think I could just throw everything in it. No matter how crazy the conversion is, if there is a path, you will get it!
How does GNU unit get the conversion tables to bootstrap, does anybody know?
My current alias for units is "units -1v -d max". This makes this improves output and uses max precision.
Is there a spreadsheet that supports units in its cells and GNU Units in formulas? Seems like that would be an amazing open source tool.
One of my favorite feature is guessing the physical quantity from the dimensions. For example:
The units definitions file also contains many interesting facts, here's an excerpt:You have: A / m You want: ? H_FIELD B_FIELD / (mu0/mu0_SI) MAGNETIZATION MAGNETIC_DIPOLE_MOMENT / VOLUME Oe oersted oe Oe oersted gauss / mu0A ! # The ampere, symbol A, is the SI unit of electric current. ampere A # It is defined by taking the fixed numerical value of the amp ampere # elementary charge, e, to be 1.602 176 634 * 10^-19 when # expressed in the unit C, which is equal to A*s. # # The previous definition was the current which produces a # force of 2e-7 N/m between two infinitely long wires a meter # apart. This definition was difficult to realize accurately. # # The ampere is actually realized by establishing the volt and # the ohm, since A = V / ohm. These measurements can be done # using the Josephson effect and the quantum Hall effect, # which accurately measure voltage and resistance, respectively, # with reference to two fixed constants, the Josephson # constant, K_J=2e/h and the von Klitzing constant, R_K=h/e^2. # Under the previous SI system, these constants had official # fixed values, defined in 1990. This created a situation # where the standard values for the volt and ohm were in some # sense outside of SI because they depended primarily on # constants different from the ones used to define SI. After # the revision, since e and h have exact definitions, the # Josephson and von Klitzing constants will also have exact # definitions that derive from SI instead of the conventional # 1990 values. # # In fact we know that there is a small offset between the # conventional values of the electrical units based on the # conventional 1990 values and the SI values. The new # definition, which brings the practical electrical units back # into SI, will lead to a one time change of +0.1ppm for # voltage values and +0.02ppm for resistance values. # # The previous definition resulted in fixed exact values for # the vacuum permeability (mu0), the impedance of free space # (Z0), the vacuum permittivity (epsilon0), and the Coulomb # constant. With the new definition, these four values are # subject to experimental error.GNU Units is an absolute favourite of mine and a true gem. I'd first learnt of it through an HN perennial, Trey Harris's "The 500 Mile Email" (61 submissions, and counting: <https://hn.algolia.com/?dateRange=all&page=0&prefix=true&que...>).
It wasn't until a decade or so of using it that I realised it was actually a units-aware calculator, and could make interesting conversions (say: how much land area you'd need to supply all US energy needs with solar power, given various factors of incident sunlight, spacing factors, panel efficiencies, etc.). kragen's comment in this thread blows away my own usage (I learned several new things reading it, which means this is a Good Day).
Note for MacOS and *BSD users: the variant of units shipping on your systems is a parlously pale shadow of the GNU version. MacOS boffins can install GNU Units via Homebrew, where it's accessed as "gunits" by default.
At some point I was looking at using a units library, but came up short because I could not find one that could convert using log scale units (which I needed). The same is True for gnu units.
It can convert from linear to log units, e.g.:
You have: 10W You want: dBm 40
but not the other way around (unless I'm missing something):
You have: 40 dBm ^ Parse error
I understand that log units are tricky to get right, but in some fields they are pretty ubiquitous.
I actually did a WebAssembly port of the GNU Units library and you can now use it in your browser.
Demo: https://yanosh.net/units-wasm/ GitHub Repo for the demo: https://github.com/yanosh-k/units-wasm GitHub Repo for the WASM project: https://github.com/yanosh-k/gnu-wasmunits
You have: 20 furlongs per fortnight
You want: miles per hour
* 0.0074404762
/ 134.4
I also highly recommend checking out https://frinklang.org/
ah, so that's how you do °C / °F ...
You have: tempF(45) You want: tempC 7.2222222Slightly related... I have once created a c++ templated class that encapsulates all SI units. Using the values of the different SI quantities, you can let the compiler perform all kinds of quantity interference or checking.
What on Earth is an "aeginamina?"[1]
(2016)
Posted a few times recently
Here's some more discussion 3 years ago: https://news.ycombinator.com/item?id=25657311
Related:
GNU Units - https://news.ycombinator.com/item?id=25657311 - Jan 2021 (203 comments)
When I run `sudo pacman -Fy units` on Arch Linux I only get a similar tool from plan9port, it's strange they took the GNU version out of the repos.
I've been learning emacs calc (my HP-48g calculator finally died) and it seems to have this built-in. It's super impressive.
It would be nice to get implemented as an extension in VScode.
> You have: 17 yards + 2 feet + 5 inches
Measuring things like this seems brain dead.
One of the best features of my HP-50G calculator is the units library.
Great utility. Almost the only thing I use Termux for nowadays.
(2016)
[dead]
gnunits*
GNU should make it's own system of measurement, best of all :)