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…
GNU Units
41–50 of 117 posts
Re: GNU Units
#42Re: GNU Units
#43 You have: tempF(45)
You want: tempC
7.2222222Re: GNU Units
#44this 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…
Just to work around the bug, you can use a local definitions file to correct it:
cat > ~/.units Re: GNU Units
#45ah, so that's how you do °C / °F ... You have: tempF(45) You want: tempC 7.2222222
Re: GNU Units
#46For 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" MiBRe: GNU Units
#47this 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,…
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-2300Re: GNU Units
#48One of the best features of my HP-50G calculator is the units library.
Re: GNU Units
#49This 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…
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