[HN Gopher] GNU Units
       ___________________________________________________________________
        
       GNU Units
        
       Author : makeworld
       Score  : 82 points
       Date   : 2023-08-03 15:39 UTC (7 hours ago)
        
 (HTM) web link (www.gnu.org)
 (TXT) w3m dump (www.gnu.org)
        
       | jwr wrote:
       | One of the best features of my HP-50G calculator is the units
       | library.
        
         | kragen wrote:
         | how does it handle the examples i posted in
         | https://news.ycombinator.com/item?id=36988917
        
       | tangus wrote:
       | Great utility. Almost the only thing I use Termux for nowadays.
        
       | cb321 wrote:
       | 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
       | 
       | [1] https://nim-lang.org/
        
         | giraffe_lady wrote:
         | F# also has units integrated into the type system. Seems like a
         | great feature though I've never used a language with it.
        
       | simne wrote:
       | GNU should make it's own system of measurement, best of all :)
        
       | darkstarsys wrote:
       | 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.
        
         | kragen wrote:
         | to my surprise, it turns out that org-mode's spreadsheet does
         | support units, because it uses emacs calc-eval. But calc seems
         | to have its own dimensional analysis engine rather than using
         | gnu units. i was hoping to get a temperature in this last
         | column, for example:                   | 3 mm | 4 kg |
         | 0.44444444 kg / mm^2 | 44.444444 kg m^2 / (s^2 mm^2) |
         | (44.444444 kg m^2 / (s^2 mm^2 stefanboltzmann))^0.25 |
         | | 2 mm | 1 kg | kg / (4 mm^2)        | 25 kg m^2 / (s^2 mm^2)
         | | (25 kg m^2 / (s^2 mm^2 stefanboltzmann))^0.25        |
         | #+TBLFM: $3=$2/$1/$1::$4=$3*(10m/s)**2::$5=($4/
         | stefanboltzmann)**(1/4)
         | 
         | (edited, previous incorrect version follows)
         | | 3 mm | 4 kg | 0.44444444 kg / mm^2 | 300 mm m^2 / s^2 | (300
         | mm m^2 / (s^2 stefanboltzmann))^0.25 |         | 2 mm | 1 kg |
         | kg / (4 mm^2)        | 200 mm m^2 / s^2 | (200 mm m^2 / (s^2
         | stefanboltzmann))^0.25 |         #+TBLFM:
         | $3=$2/$1/$1::$4=$1*(10m/s)**2::$5=($4/ stefanboltzmann)**(1/4)
         | 
         | similarly here i was hoping to get the time until the laptop
         | charges and i guess i sort of did but not really
         | | 22.8 Wh | 16.8 Wh | 6. Wh | 7.4W | 0.81081081 Wh / W |
         | #+TBLFM: $3=$1-$2::$5=$3/$4
        
       | chungy wrote:
       | 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" MiB
        
       | tomas789 wrote:
       | 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.
        
         | jeramey wrote:
         | I'll second that. I work in the renewable energy space where we
         | get all manner of atmospheric and power data in a wide variety
         | of units depending on the data source, so Pint is incredibly
         | useful in normalizing them as well as making it clear in the
         | code what and how unit conversion is happening. The fact that
         | it integrates fairly nicely with Pandas and Numpy is great,
         | too.
        
       | dang wrote:
       | Related:
       | 
       |  _GNU Units_ - https://news.ycombinator.com/item?id=25657311 -
       | Jan 2021 (203 comments)
        
       | makeworld wrote:
       | My current alias for units is "units -1v -d max". This makes this
       | improves output and uses max precision.
        
       | ChrisArchitect wrote:
       | (2016)
        
       | ChrisArchitect wrote:
       | (2016)
       | 
       | Posted a few times recently
       | 
       | Here's some more discussion 3 years ago:
       | https://news.ycombinator.com/item?id=25657311
        
         | seabass-labrax wrote:
         | It's not (2016) in my opinion - this page was last updated
         | then, but the most recent release of the software was in 2022.
        
       | krupan wrote:
       | I've been learning emacs calc (my HP-48g calculator finally died)
       | and it seems to have this built-in. It's super impressive.
        
         | kragen wrote:
         | i was excited by your comment but disappointingly emacs calc
         | seems to have its own, less powerful unit conversion system
         | https://news.ycombinator.com/item?id=36991392
        
       | Qem wrote:
       | This 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.
        
         | krger wrote:
         | >This tool is underrated. Failing to deal with units conversion
         | already crashed a Mars probe
         | 
         | The mistake there was that they were unaware that they had to
         | make the unit conversion, not that they did it wrong.
         | 
         | No tool can, by itself, overcome your ignorance of its
         | necessity.
        
           | nequo wrote:
           | > No tool can, by itself, overcome your ignorance of its
           | necessity.
           | 
           | A type system that understands units of measurement can help:
           | 
           | https://learn.microsoft.com/en-us/dotnet/fsharp/language-
           | ref...
        
           | Qem wrote:
           | > The mistake there was that they were unaware that they had
           | to make the unit conversion, not that they did it wrong.
           | 
           | I think the root cause here was continued use of medieval
           | units, instead of just standardizing on the metric system as
           | it's already done around nearly the entire world.
        
             | [deleted]
        
             | extraduder_ire wrote:
             | Have you ever accidentally set your calculator to gradians?
             | We were warned about it when doing trigonometry in school,
             | the first time we had to go between degrees and radians.
        
             | fest wrote:
             | Even if it was all metric, in embedded systems you often
             | have to deal with the same measurements in different units,
             | like angles in radians, degrees, centidegrees, length in
             | mm, m, cm, due to various reasons (mostly historical, like
             | integer math being faster than floating point math).
             | 
             | It is getting less frequent in modern code bases that
             | target 32-bit MCUs with hardware-floating point support,
             | but converting large codebases
        
               | gumby wrote:
               | > Even if it was all metric, in embedded systems you
               | often have to deal with the same measurements in
               | different units, like angles in radians, degrees,
               | centidegrees, length in mm, m, cm, due to various reasons
               | (mostly historical, like integer math being faster than
               | floating point math).
               | 
               | It's also cultural - different fields use different SI
               | units for historical or practical reasons.
               | 
               | My second year at MIT I was in a program (16.001 & 2)
               | that had different classes using cgs, mks, and mills.
               | They all met in the same classroom (different times of
               | course!), so there was no spacial reminder. But we all
               | survived.
        
         | theamk wrote:
         | The idea of using units is underrated, yes. More programming
         | languages should be offer support for units, and more program
         | should be using them.
         | 
         | That particular tool, "GNU Units"? Nope. It is pretty good
         | command-line calculator (especially if you give inputs on
         | command line so that history is preserved), but it is not
         | really scriptable, and you'd _definitely_ want to avoid all
         | manual calculations in any sort of important process.
        
           | kragen wrote:
           | it's somewhat scriptable, and it keeps its own history; i
           | usually use it interactively to get better tab-completion.
           | that also makes search with ^r provide more relevant search
           | hits
           | 
           | as an example of scriptability, i just added this function to
           | ~/.units                   # note that theta is the angle
           | from the central axis of the cone to its side
           | conesolidangle(theta) units=[radian;sr] range=[0,) 2 pi (1 -
           | cos(theta)) sr ; \             acos(1 -
           | conesolidangle/sr/2/pi)
           | 
           | (sadly it is not smart enough to figure out the inverse
           | formula itself, even in a simple acyclic case like this)
           | 
           | with this i can calculate, for example, the convergence angle
           | required for concentrated sunlight to melt iron
           | (asymptotically, assuming no heat losses to conduction or
           | convection)                   You have: 2
           | ~conesolidangle(conesolidangle(asin(sunradius/sundist))
           | tempC(1538)**4 stefanboltzmann / (1000W/m2))         You
           | want: dms                 13 deg + 10 arcmin + 34.428619
           | arcsec
           | 
           | it would be highly desirable to have conditionals and loops,
           | of course, or even numpy-style vectors with broadcasting, as
           | well as either functions of more than one argument or higher-
           | order functions, and it doesn't have any of those
        
           | parekhnish wrote:
           | Worth looking at: https://github.com/aurora-opensource/au
           | It's a C++ library for handling physical quantities (and
           | subsequent unit conversions)
        
       | Rayhem wrote:
       | I 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.
        
         | cb321 wrote:
         | Yes - you haven't seen the full scope until you confront unit
         | system conversions as alluded to in my other comment
         | (https://news.ycombinator.com/item?id=36988497).
         | 
         | There should also be conversions to/from SI|CGS and "natural
         | units" (particle physics) and "gravitational units" (general
         | relativity - G=c=1).
         | 
         | The "input/output" can be a bit more subtle, too - since you
         | may need to tell the converter the abstract physical kind/"meta
         | type" of the thing like "energy" or "momentum" or "charge" to
         | fully define what might happen (and in some ideal world get
         | back an expression with powers of G's and c's in there
         | _symbolically_ rather than only numerically). Some of this
         | shows up in an unresolved issue on that Nim library I
         | mentioned[1]: https://github.com/SciNim/Unchained/issues/8
         | 
         | EDIT: { One reason to preserve a symbolic capability is that
         | some constants have resisted precise measurement for centuries
         | - G is still only known to about 5 decimals [2] - and you don't
         | want round-trip unit conversion to add such errors to the
         | calculation. }
         | 
         | [1] https://news.ycombinator.com/item?id=36988225
         | 
         | [2]
         | https://en.wikipedia.org/wiki/Gravitational_constant#Modern_...
        
       | rnhmjoj wrote:
       | One of my favorite feature is guessing the physical quantity from
       | the dimensions. For example:                   You have: A / m
       | You want: ?         H_FIELD       B_FIELD / (mu0/mu0_SI)
       | MAGNETIZATION MAGNETIC_DIPOLE_MOMENT / VOLUME         Oe
       | oersted         oe            Oe         oersted       gauss /
       | mu0
       | 
       | The units definitions file also contains many interesting facts,
       | here's an excerpt:                   A         !      # 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.
        
       | mrbonner wrote:
       | 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?
        
         | cb321 wrote:
         | It's more like a 2-level situation for most things with a
         | little more structure than you might realize. There are
         | "physical kinds" or meta types like "energy" and then different
         | concrete units those can be which allow conversion.
         | 
         | The physical kind is a point in an N-dimensional rational space
         | of exponents of base units, such as Mass * Distance ^2 *
         | Time^-2 or (1,2,-2) for energy (maybe with some carry over ^0s
         | for unused slots of a >3D meta-type space). Additive (like add,
         | subtract, compare, and convert) are only meaningful at the same
         | point in that lattice. If you are interested in learning more,
         | this is all a part of dimensional analysis:
         | https://en.wikipedia.org/wiki/Dimensional_analysis .
         | 
         | Even the dimensionality of that rational exponent space (the
         | "unit system", if you will) is more of convenience / convention
         | than fundamental. https://en.wikipedia.org/wiki/Planck_units
         | clobber most things away leaving only 1 dimension (and a
         | tendency for complex rational exponents). Meanwhile, the SI
         | unit system is very "dimension promiscuous" (mass, length,
         | time, electric current, temperature, amount of substance,
         | luminous intensity) [1] to avoid non-integer exponents (but you
         | cannot really forever since as soon as some formula has some
         | square some solution of it has some root that probably gets you
         | a 1/2 exponent).
         | 
         | There are some situations with not purely "conversion factor"
         | scale offsets like thermal units (e.g. Celsius to Fahrenheit)
         | that people often describe in math-ese as "affine conversions".
         | Something like GNU Units attends these things, but they are
         | kind of "conversion only" orphan step-children more than "real"
         | types which "compose better". In physics formulae one will
         | often only care about delta-Temperature, not levels, for
         | example.
         | 
         | EDIT: The implicit creation of a potentially brand new type
         | _any time you multiply | divide_ two extant things is,
         | incidentally, why you need either a dynamic or a very powerful
         | static type system to express these things.
         | 
         | [1] https://en.wikipedia.org/wiki/International_System_of_Units
        
         | kragen wrote:
         | no dude you're seriously overcomplicating the problem
         | 
         | it's just a finite-dimensional vector space over Q
         | 
         | https://en.wikipedia.org/wiki/Dimensional_analysis#Mathemati...
         | 
         | the conversion tables are in /usr/share/units/definitions.units
         | (or previously /usr/share/misc/units.dat)
         | 
         | they are the result of many years of careful scholarship by
         | adrian mariano
        
         | simplicio wrote:
         | Think a spoke/hub type thing would be a lot easier. Just
         | convert inputs to SI, then from SI to the output.
        
           | seabass-labrax wrote:
           | Parent was suggesting a hash table lookup though, in which
           | case the topology of the graph would be irrelevant. The
           | number of entries in the table would be constant regardless
           | of whether the original graph was connected with the fewest
           | number of edges or with the greatest number of edges (a
           | complete graph, which is what the table would be encoding).
        
         | ygra wrote:
         | Wouldn't the most sensible option just be too have the SI units
         | at the center and everything else heaving a conversion edge to
         | that? While intriguing, there is probably no need to make that
         | graph any denser.
        
           | alfalfasprout wrote:
           | Yep. Especially if using a bignum library to keep sufficient
           | precision during the intermediate conversion.
        
           | mrbonner wrote:
           | Then how do you deal with non-SI units, like money?
        
             | alfalfasprout wrote:
             | Notice how money isn't handled (at least per the examples)
             | by GNU Units. Because currency (and fungible financial
             | instruments in general) have variable exchange rates.
             | 
             | For currency conversion, it's a lot more tricky because
             | there's many ways to convert. Eg; if I want to go from CHF
             | to USD there's a lot of CHF->USD volume and there are
             | market rates for that exact conversion. But between eg; SGD
             | (singapore dollar) and Peruvian Soles (PEN) the market is a
             | lot smaller so it may be actually beneficial to do SGD ->
             | USD -> PEN.
             | 
             | Typically this means ingesting a feed of real time prices +
             | any fees and then doing a limited-hop graph traversal.
        
               | kragen wrote:
               | money is handled by gnu units
               | 
               | the base unit is the us dollar
               | 
               | this is arguably incorrect but inarguably useful
               | 
               | from the man page:
               | 
               | > _The units program database includes currency exchange
               | rates and prices for some precious metals. Of course,
               | these values change over time, sometimes very rapidly,
               | and 'units' cannot provide real-time values. To update
               | the exchange rates, run 'units_cur', which rewrites the
               | file containing the currency rates, typically '
               | /var/lib/units/currency.units' or
               | '/usr/local/com/units/currency.units' on a Unix-like
               | system or 'C:\Program Files
               | (x86)\GNU\units\definitions.units' on a Windows system._
        
               | mrbonner wrote:
               | It is interesting because I see a file `currency.units`
               | in the source distribution. It has the list of all
               | countries' currencies normalized to USD. If Units doesn't
               | deal with currency, why does it maintain this conversion
               | file? And, I agree that the exchange rate varies day to
               | day. But, this may provide an estimate conversion.
        
             | seabass-labrax wrote:
             | You can't really convert units of money to any other units,
             | so I'm not convinced of the utility of money conversion in
             | this kind of tool.
             | 
             | US Dollars would be connected to US Cents in the graph, and
             | Pounds Sterling and New Pence would be connected to each
             | other too, but those two subgraphs would be entirely
             | disconnected from each other and from any SI unit like
             | distance or mass.
        
             | tadfisher wrote:
             | Money (currency, really) is a whole forest of units with
             | bespoke scales, arithmetic, and market-driven conversion
             | logic. If you are converting money to other units with a
             | library, you are almost certainly doing it wrong, or are
             | operating at a level of abstraction much higher than my
             | puny brain can fathom.
        
             | qbrass wrote:
             | Convert to USD then back. Which is what Units does.
        
             | simplicio wrote:
             | Just pick a unit as the "standard" for that type of
             | quantity.
        
         | mrbonner wrote:
         | I get it that some suggest the graph is a complicated/over-
         | engineer while other suggest just stick to SI. Well, my
         | rationale is that not everything has a SI conversion, and
         | simple SI/hub/spoke would need you to maintain a unit -> SI (or
         | base unit like USD in currency conversion).
         | 
         | What I like about the graph solution is that you don't have to
         | use SI or base unit at all! If your graph has km -> m, now you
         | add (updating your graph) for m -> feet, you could traverse
         | from km -> feet. Later on, you can add nautical mile -> feet,
         | using this graph you could basically get km -> nautical mile if
         | you need to.
        
       | kragen wrote:
       | 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?                   You have: (22.8 Wh - 16.8 Wh)/7.4W
       | You want: time                 48 min + 38.918919 sec
       | 
       | how long will a 2000mAh 18650 cell take to discharge at 2.5
       | watts, using a nominal voltage of 3.7 volts?
       | You have: 3.7 V 2 amp hour / 2.5 watt         You want: time
       | 2 hr + 57 min + 36 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 / circlearea(half 18 mm) 65 mm         You
       | want: MJ/                 * 1.6105936                 /
       | 0.62088909
       | 
       | what's the specific energy of stoichiometrically mixed
       | oxyhydrogen fuel?                   You have: 44000 J/mol / ((2
       | hydrogen + oxygen)g/mol)         You want: MJ/kg
       | * 2.4423711                 / 0.40943818
       | 
       | okay but how much volume? say at atmospheric pressure?
       | You have: 3 mol gasconstant tempC(20) / 1 atm         You want: l
       | * 72.165351                 / 0.013857066
       | 
       | so that's how much energy density?                   You have:
       | 44kJ/_         You want: J/l                 * 609.71089
       | / 0.0016401216
       | 
       | (i may be off by a factor of 2 here)
       | 
       | how much energy can this capacitor hold?                   You
       | have: half (10V)**2 47 uF         You want: mJ                 *
       | 2.35                 / 0.42553191
       | 
       | how much energy density is that?                   You have: half
       | (10V)**2 47 mF / 15mm circlearea(3mm)         You want: J/
       | * 5.5409499                 / 0.18047447
       | 
       | 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 gigapascals                   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.6847624
       | 
       | note that this is the _radius_ of the cable, not its diameter!
       | 
       | the datasheet says this 400x240 display uses 175 mW if all the
       | pixels flip once per second and 60 mW for a static display. how
       | much energy is that per pixel flip?                   You have:
       | (175 uW - 50 uW) / 400 240 1 Hz         You want: nJ
       | * 1.3020833                 / 0.768
       | 
       | if i overclock it to 60 fps how much power will it use?
       | You have: 60 Hz 400 240 1.3nJ         You want: mW
       | * 7488                 / 0.00013354701
       | 
       | and how many pixels is its diagonal?                   You have:
       | 400**2+240**2         You want:                  Definition:
       | 217600         You have: _**.5         You want:
       | Definition: 466.47615
       | 
       | what is the visual angle subtended by the sun as seen from earth?
       | You have: 2 sunradius/sundist         You want: milliradians
       | * 9.3049358                 / 0.10746984         You have: _
       | You want: dms                 31 arcmin + 59.280781 arcsec
       | 
       | okay, how does that compare to the moon?                   You
       | have: moonradius 2 / moondist         You want:
       | Definition: 0.0090426639
       | 
       | 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 bigger
       | You have: moonradius 2 / moondist_min         You want:
       | Definition: 0.0097530864
       | 
       | what percentage of this copper sulfate is actual copper?
       | You have: copper / (copper + (sulfur + 4 oxygen))         You
       | want: %                 * 39.813395                 / 0.025117175
       | 
       | 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: 100 thousand 128
       | MiB/53 years         You want: bytes/second                 *
       | 8024.8943                 / 0.00012461223
       | 
       | how much fuel will this truck need to get across the country?
       | You have: 4000 km / (6.5 miles/gallon)         You want: l
       | * 1447.4744                 / 0.00069085852
       | 
       | how much is that per kilogram of lettuce or sodium lauryl sulfate
       | or whatever?                   You have: _/28 tonnes         You
       | want: ml/kg                 * 51.695513                 /
       | 0.019344039
       | 
       | okay, but how much energy is 52 m of diesel per kg of lettuce?
       | You have: _ 38.6 kJ/l         You want: kJ/kg                 *
       | 1.9954468                 / 0.5011409
       | 
       | how much data can i transfer overnight during unmetered hours on
       | a 2400-baud modem?                   You have: 8 hours 2400 bps
       | You want: MB                 * 8.64                 / 0.11574074
       | 
       | how much power does the earth receive from the sun, assuming a
       | solar constant of 1400 W/m2?                   You have: 1400
       | W/m**2 * circlearea(earthradius)         You want: petawatts
       | * 178.52313                 / 0.0056015152
       | 
       | 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 / stefanboltzmann)**(1/4)         You
       | want: tempC                 123.24583
       | 
       | how about here in buenos aires at the winter solstice? first,
       | what angle is the sun at anyway? we're at 34deg36' south, and the
       | sun's latitude at the solstice is 23deg26'                   You
       | have: 34deg + 36' + 23deg + 26'         You want: dms
       | 58 deg + 2 arcmin
       | 
       | so that reduces the peak insolation to how much? here underneath
       | the atmosphere we only get 1kW/m2                   You have:
       | cos(_) 1000 W/m^2         You want: W/m^2                 *
       | 529.4258                 / 0.0018888388
       | 
       | and that would be what temperature in equilibrium?
       | You have: (_/stefanboltzmann)**(1/4)         You want: tempC
       | 37.698189
       | 
       | (integrating the sun's angle over the course of the day as the
       | earth rotates is sadly beyond its capacities)
       | 
       | how 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.5C//kWh because of solar                   You have: 1500
       | kcal/day * 16 years * 2.5 cents/kWh         You want:
       | Definition: 254.69556 US$
       | 
       | what's the surface area of a 300mm x 400mm x 150mm backpack? like
       | how much cloth?                   You have: 2 (300mm 400mm +
       | 400mm 150mm + 150mm 300mm)         You want:
       | Definition: 0.45 m^2
       | 
       | okay but in cm2                   You have: _         You want:
       | cm2                 * 4500                 / 0.00022222222
       | 
       | what's the electrical impedance of a 1000 mF cap at an audio
       | highpass frequency of 20Hz?                   You have: 1/(2 pi
       | 20 Hz 1000 uF)         You want: ohms                 * 7.9577472
       | / 0.12566371
       | 
       | 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 MO?                   You have: 100 pF 1
       | megohm         You want: ms                 * 0.1
       | / 10
       | 
       | okay. so how long will an 0.1mF cap take to discharge through a
       | 100kO resistor from 5 volts down to a 1.3 volt threshold?
       | You have: ln(5V/1.3V) .1 uF 100kilohm         You want: ms
       | * 13.470736                 / 0.074234991
       | 
       | 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: log(1.8mV/1.5V)/log(2)
       | You want:                  Definition: -9.7027499
       | 
       | if this oxygen absorber contains 7 grams of iron which oxidizes
       | to Fe2O3, 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 liter                   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
       | 
       | i've lost 7 kg over the last two months; how much of a caloric
       | deficit does that represent in my diet?                   You
       | have: 7 kg 3500kcal/pound / 2 months         You want: kcal/day
       | * 887.30034                 / 0.0011270141
       | 
       | if you were to spread the moon evenly over russia, how deep would
       | it be?                   You have: spherevol(moonradius) /
       | area_russia         You want:                  Definition:
       | 1286134.4 m
       | 
       | how big is nigeria compared to massachusetts?
       | You have: area_nigeria/area_massachusetts         You want:
       | Definition: 33.793093
       | 
       | how many ounces of platinum is a ton of oil worth at 40 dollars
       | per megawatt hour?                   You have: tonoil 40
       | dollars/MWh         You want: platinumounce                 *
       | 0.58368883                 / 1.7132416
       | 
       | or in grams?                   You have: tonoil 40 dollars/MWh /
       | platinumprice         You want: g                 * 18.154752
       | / 0.055081997
        
         | chungy wrote:
         | Trying your examples, especially considering that the
         | elliptical orbit of the earth likewise causes the Sun's angular
         | diameter change depending on where our orbit is, I found that
         | Units current has a buggy definition of moondist_min and
         | moondist_max. It's defined in the definitions file as 356.371
         | km and 406.720 km respectively. These should be Mm! (Or remove
         | the period, either will work)
         | 
         | Just to work around the bug, you can use a local definitions
         | file to correct it:                   cat > ~/.units <<EOF
         | moondist_min 356.371 Mm         moondist_max 406.720 Mm
         | EOF
        
           | kragen wrote:
           | interesting, looks like an effort to improve the precision
           | resulted in a factor of 1000 error! `help moondist_max` shows
           | me considerably less precise values:
           | sundist                 1.0000010178 au # mean earth-sun
           | distance         moondist                3.844e8 m       #
           | mean earth-moon distance         sundist_near
           | 1.471e11 m      # earth-sun distance at perihelion
           | sundist_far             1.521e11 m      # earth-sun distance
           | at aphelion         moondist_min            3.564e8 m       #
           | approximate least distance at
           | #    perigee 1901-2300         moondist_max
           | 4.067e8 m       # approximate greatest distance at
           | #    apogee 1901-2300
        
             | chungy wrote:
             | Where are you typing help to get that output?
        
               | kragen wrote:
               | at the units prompt                   You have: help
               | moondist_max
               | 
               | then i scrolled up a few lines in less
        
               | chungy wrote:
               | I could've sworn I tried and didn't get anything. Now it
               | is working. I don't know what I did! (running version
               | 2.22, at any rate)
        
               | kragen wrote:
               | sweet
               | 
               | search is also pretty nice                   You have:
               | search gallon         alegallon      beergallon
               | beergallon     282 UKinch^3         brgallon
               | 4.54609 l         drygallon      1|2 uspeck
               | gallon         usgallon         imperialgallon brgallon
               | irishgallon    217.6 UKinch^3         scotsgallon
               | 827.232 UKinch^3         usgallon       231 in^3
               | winegallon     231 UKinch^3
        
       | rany_ wrote:
       | 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.
        
         | krylon wrote:
         | I was about to say the same. ;-) Except I use the Qt UI.
        
       | m463 wrote:
       | ah, so _that 's_ how you do degC / degF ...                   You
       | have: tempF(45)         You want: tempC                 7.2222222
        
         | ThinkingGuy wrote:
         | Thanks, that was puzzling me at first.
        
       ___________________________________________________________________
       (page generated 2023-08-03 23:00 UTC)