Live data from Hacker News

GNU Units

gnu.org

41–50 of 117 posts

Re: GNU Units

#41

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…

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.

Re: GNU Units

#42
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.

Re: GNU Units

#43
ah, so that's how you do °C / °F ...

    You have: tempF(45)
    You want: tempC
            7.2222222

Re: GNU Units

#44
post #31

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 de…

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 

Re: GNU Units

#46
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

Re: GNU Units

#47
post #44
post #31

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 de…

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,…

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

Re: GNU Units

#49
post #22
post #2

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.

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 impor…

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
Post reply on HN