12 ms·
GNU Units
- Qem 3y agoThis 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-story.html 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 3y ago>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 3y ago> 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-reference/units-of-measure https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref...
- klausa 3y agoThat still requires you to know about its existence. It's perfectly possible to write F# code without those and messing up units conversion.
- nequo 3y agoSomeone on the team needs to know about it. That person needs to set up the API to expect properly typed inputs. Others can remain ignorant about units of measurement and the compiler will educate them. F# has this built in but it can be achieved with libraries in some other languages. For example, in Haskell with the dimensional package[1]: import Numeric.Units.Dimensional.Prelude import Numeric.Units.Dimensional.NonSI (mile) speedLimit :: Velocity Double speedLimit = 30 *~ (mile / hour) main :: IO () main = do let speed1 = 35 *~ (kilo meter / hour) let speed2 = 35 *~ (mile / hour) let speed3 = 35 print (speed1 <= speedLimit) print (speed2 <= speedLimit) print (speed3 <= speedLimit) GHC will give you an error because `speed3` is mistyped. [1] https://hackage.haskell.org/package/dimensional https://hackage.haskell.org/package/dimensional
- midoridensha 3y agoYou're not getting it. The Mars probe didn't crash because of bad unit conversion. It crashed because there were no units in the data!!! Go read about it yourself. NASA got some data from a contractor. The data had no units at all. The contractor assumed the data to be in some kind of US-standard units. NASA got these raw numbers and assumed they were in some kind of SI units. Having enforced units in your language isn't going to help in this situation at all. They weren't exchanging code, they were exchanging raw data, or more specifically, a table with a bunch of numbers on it. The people at NASA simply assumed some units (instead of calling the contractor and asking), and they would have done this in your scenario too.
- Qem 3y ago> 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.
- fest 3y agoEven 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 3y ago> 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.
- deleted 3y ago[deleted]
- extraduder_ire 3y agoHave 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.
- theamk 3y agoThe 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.
- parekhnish 3y agoWorth looking at: https://github.com/aurora-opensource/au https://github.com/aurora-opensource/au It's a C++ library for handling physical quantities (and subsequent unit conversions)
- kragen 3y agoit'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
- marbu 3y ago> More programming languages should be offer support for units, and more program should be using them. There is some solution for most programming languages: https://gmpreussner.com/research/dimensional-analysis-in-programming-languages https://gmpreussner.com/research/dimensional-analysis-in-pro... How well it works mostly depends on features of a programming language or it's compiler. That said it's rare for a programming language to have a type system with extra features and unit checking support in it's standard library like F# or GNAT does: https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/units-of-measure https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref... https://gcc.gnu.org/onlinedocs/gnat_ugn/Performing-Dimensionality-Analysis-in-GNAT.html https://gcc.gnu.org/onlinedocs/gnat_ugn/Performing-Dimension...
- makeworld 3y agoMy current alias for units is "units -1v -d max". This makes this improves output and uses max precision.
- mrbonner 3y agoI 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?
- simplicio 3y agoThink a spoke/hub type thing would be a lot easier. Just convert inputs to SI, then from SI to the output.
- seabass-labrax 3y agoParent 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 3y agoWouldn'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.
- mrbonner 3y agoThen how do you deal with non-SI units, like money?
- cb321 3y agoUnits 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 https://github.com/SciNim/Unchained [1] https://nim-lang.org/ https://nim-lang.org/
- giraffe_lady 3y agoF# also has units integrated into the type system. Seems like a great feature though I've never used a language with it.
- augusto-moura 3y agoJust for curiosity, what Nim does that other languages with operator overloading wouldn't do? Aside from the "number.unit" syntax, you could do some trickery to get units comparison and conversions even on C++
- delta_p_delta_x 3y ago> units comparison and conversions even on C++ See mp-units[1]. [1]: https://github.com/mpusz/mp-units https://github.com/mpusz/mp-units
- Conscat 3y agoI work in large C++ codebase for a suite of physics simulation software, and there are like 200 something strongly typed arithmetic units here.
- cb321 3y agoAnything with a finite (200 is small even) number of units misses the algebraic structure of the problem mentioned in https://news.ycombinator.com/item?id=36988497 https://news.ycombinator.com/item?id=36988497 wherein multiplying|dividing two things gives you a (potentially) new unit which implies an open ended "space" of units. To be concrete (hah!), in C++ a template meta-type with 12 signed integer parameters (6 numerators & 6 denominators for rational exponents of SI base units) might be one way to model it. Unlike C++ template stuff, Nim macros (like Lisp macros) makes metaprogramming more like procedural programming - just against abstract syntax trees. I think that helps to shield some of this type complexity from users, but the documentation README https://github.com/SciNim/Unchained https://github.com/SciNim/Unchained does better job than I can in an HN comment. Of course, for unit system conversion, the number of dimensions (6 in SI, 3 in CGS/Gaussian) changes. So, for full generality you need compile-time (if you want static type integration/CT errors) linear algebra over a rational field (at least & conventionally) to project|inverse project. That might be theoretically possible in C++. I would think it very un-fun and unlikely to ever have been done. There's probably a Mathematica package, though. EDIT: It seems that mp-units mentioned in a sibling comment has some rare support for varying unit systems (no GR or Planck ones, but at least "natural" & "hep" & not sure about system-conversion or just system-use). That lib also leans very heavily on many very modern C++ (C++20 & beyond) features, has constexpr everywhere in use cases. I am not sure I would say it shields users wonderfully or makes it seem like units are very ordinary types. Just looking at mp-units/example/VARIOUS.cpp makes it look syntactically very noisy, verbose, and a lot to learn.
- ChrisArchitect 3y ago(2016) Posted a few times recently Here's some more discussion 3 years ago: https://news.ycombinator.com/item?id=25657311 https://news.ycombinator.com/item?id=25657311
- seabass-labrax 3y agoIt's not (2016) in my opinion - this page was last updated then, but the most recent release of the software was in 2022.
- hedora 3y agoIf we’re going by age of article, (1997) is probably closer: http://ftp.gnu.org/gnu/units/ http://ftp.gnu.org/gnu/units/ Though, back then, most GNU utils were copies of older unix stuff, so (1980) or even (1960) wouldn’t surprise me.
- ChrisArchitect 3y ago(2016)
- rnhmjoj 3y agoOne 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.
- Rayhem 3y agoI 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 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 3y agoYes - 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 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 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 https://news.ycombinator.com/item?id=36988225 [2] https://en.wikipedia.org/wiki/Gravitational_constant#Modern_value https://en.wikipedia.org/wiki/Gravitational_constant#Modern_...
- kragen 3y agothis 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 μF / 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 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? 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: μW * 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/m²? 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 34°36’ south, and the sun's latitude at the solstice is 23°26’ You have: 34° + 36' + 23° + 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/m² 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.5¢/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 × 400mm × 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 cm² You have: _ You want: cm2 * 4500 / 0.00022222222 what's the electrical impedance of a 1000 μF 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 MΩ? You have: 100 pF 1 megohm You want: ms * 0.1 / 10 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: 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 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 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
- jwr 3y agoOne of the best features of my HP-50G calculator is the units library.
- kragen 3y agohow does it handle the examples i posted in https://news.ycombinator.com/item?id=36988917 https://news.ycombinator.com/item?id=36988917
- darkstarsys 3y agoIs 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 3y agoto 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
- kalid 3y agoNot a full spreadsheet, but I have a passion project that can support units: https://instacalc.com/56734 https://instacalc.com/56734 I wanted a quick, shareable "back of the envelope" tool.
- tomas789 3y agoOnly 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 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 3y agoI'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.
- jkrubin 3y agoI will third that and add that I use pint regularly and currently work in non-renewable energy.
- vegetablepotpie 3y agoUnrelated question. I was recently appointed to a citizens energy commission and I'm finding my self modeling energy use and generation in Python. I'm curious if you would suggest any models of residential and commercial energy consumption and renewable energy generation. I'm currently generating a lot of my own from scratch and I'm being (rightly) criticized by my colleagues to use something off the shelf.
- jeramey 3y agoIf you're looking for something turn-keyish, you might be able to get some help with this from one or more of the big players in the renewable energy analysis and forecasting space, including (in no particular order) DNV, Vaisala, Bloomberg, and Ventyx. Beware, their offerings can get pretty expensive and there's often no standard list pricing. Also, I strongly encourage you to always do your own validation of any model data they might give you, so the work you're doing to produce your own models is probably not wasted.
- tangus 3y agoGreat utility. Almost the only thing I use Termux for nowadays.
- rany_ 3y agoI personally use Qalculate (https://qalculate.github.io/ 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 3y agoI was about to say the same. ;-) Except I use the Qt UI.
- m463 3y agoah, so that's how you do °C / °F ... You have: tempF(45) You want: tempC 7.2222222
- ThinkingGuy 3y agoThanks, that was puzzling me at first.
- somat 3y agoTemperature is weird. every other measurement scale starts at 0 but nether C nor F does. you have to use kelvin or rankine for that. This throws a big wrench into the calculation engine as now it has to support offsets for this one single use case. In fact openbsd units still does not support the C to F calculation.
- PaulDavisThe1st 3y agoIt's even more weird than that. units(1) can compute "starting at T Celsius, if i add N degrees celsius, how many degrees Fahrenheit did I add? and defaults to this for naive attempts to convert between the two, AND "what is X Fahrenheit in Celsius?" That is, it can convert between delta-C and delta-F, and also between absolute C and F.
- kragen 3y agothis one single use case ?! $ units Currency exchange rates from FloatRates (USD base) on 2023-08-03 3539 units, 109 prefixes, 111 nonlinear units You have: dBm(0) You want: Definition: 0.001 kg m^2 / s^3 You have: pH(0) You want: Definition: 1000 mol / m^3 You have: gasmark(0) Argument of function outside domain You have: gasmark(0.25) You want: Definition: 380.37222 K You have: gasmark(0.5) You want: Definition: 394.26111 K You have: gasmark(0.75) You want: Definition: 401.20556 K You have: gasmark(1) You want: Definition: 408.15 K You have: gasmark(1.25) You want: Definition: 411.62222 K You have: shoesize_men(0) You want: Definition: 0.20955 m You have: shoesize_men Definition: shoesize_men(n) = shoe_men0 + n shoesize_delta n is dimensionless You have: bril(0) You want: Definition: 2.5110222e-27 cd / m^2 You have: airmass Definition: airmass(alt) = 1 / (sin(alt) + 0.50572 (alt / degree + 6.07995)^-1.6364) defined for 0 degree <= alt <= 90 degree You have: airmass(0 degrees) You want: Definition: 37.919608 You have: atm_transmissionz Definition: atm_transmissionz(zenith) = exp(-extinction_coeff airmassz(zenith)) defined for 0 degree <= zenith <= 90 degree You have: atm_transmissionz(34 degree) You want: Definition: 0.77637004 You have: atm_transmissionz(0 degree) You want: Definition: 0.81063327 You have: vmag(-1.46) # Sirius You want: Definition: 9.746164e-06 cd sr / m^2 You have: vmag(0) # Vega You want: Definition: 2.54e-06 cd sr / m^2 You have: baume(0) You want: Definition: 1000 kg / m^3 You have: search gauge brwiregauge <piecewise linear> drillgauge <piecewise linear> gaugepressure <nonlinear> plategauge <piecewise linear> screwgauge <nonlinear> standardgauge 4 ft + 8.5 in stdgauge <piecewise linear> wiregauge <nonlinear> zincgauge <piecewise linear> You have: plategauge(0) You want: Definition: 0.0079375 m You have: wiregauge(0) You want: Definition: 0.0082514628 m You have: sugar_bp(tempF(250)) # candy boiling point You want: Definition: 1475.0252 kg / m^3 You have: degF(30) You want: sugar_conc_bpe # computed via this 86.975291 You have: sugar_conc_bpe Definition: interpolated table with points sugar_conc_bpe(0) = 0 K sugar_conc_bpe(5) = 0.0788 K sugar_conc_bpe(10) = 0.169 K sugar_conc_bpe(15) = 0.2729 K ... sugar_conc_bpe(99.6) = 70.1448 K sugar_conc_bpe(99.7) = 76.7867 K You have: apidegree(0) # petroleum degree You want: Definition: 1076.0456 kg / m You have: ipv4subnetsize(24) You want: Definition: 256 You have: ipv4subnetsize(26) You want: Definition: 64 You have: gaugepressure(0 psi) You want: psi * 14.695949 / 0.068045964 nonlinear and even non-affine measurement units are everywhere man
- chungy 3y agoThis 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
- Affric 3y agoThis is highly cursed. Hardware manufacturers of the 90s have a lot to answer for with regards to binary prefix units.
- simne 3y agoGNU should make it's own system of measurement, best of all :)
- krupan 3y agoI've been learning emacs calc (my HP-48g calculator finally died) and it seems to have this built-in. It's super impressive.
- kragen 3y agoi 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 https://news.ycombinator.com/item?id=36991392
- dang 3y agoRelated: GNU Units - https://news.ycombinator.com/item?id=25657311 https://news.ycombinator.com/item?id=25657311 - Jan 2021 (203 comments)
- lolsowrong 3y agognunits*
- Vecr 3y agoWhen 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.
- makeworld 3y agoYeah looks like you need to install `units` from AUR.
- broodbucket 3y agoWithout looking into it at all, it probably just didn't have an active package maintainer.
- SushiHippie 3y agoThe author of the AUR package, removed it from the community repo and moved it to the AUR. And now it has another maintainer in the AUR. The original maintainer still maintains 2185 packages [2]. Can't find an explanation why though. [0]: https://github.com/archlinux/svntogit-community/commit/2b5eca466744e2c29b969f4d19eb774905e19fdb https://github.com/archlinux/svntogit-community/commit/2b5ec... [1]: https://aur.archlinux.org/cgit/aur.git/commit/?h=units&id=e6783c67c631d2f31d7cf975c9934c0800ef2ce0 https://aur.archlinux.org/cgit/aur.git/commit/?h=units&id=e6... [2]: https://archlinux.org/packages/?packager=arojas https://archlinux.org/packages/?packager=arojas
- broodbucket 3y agoInteresting! Good sleuthing, that is odd. Guessing arojas just didn't want to deal with it any more so they moved it to the AUR and handed it over to someone else straight away. Maybe it had some quirk that made it not worth the time, though I dunno how it would, there's only a new release of units roughly once a year. http://ftp.gnu.org/gnu/units/ http://ftp.gnu.org/gnu/units/
- andsoitis 3y ago> You have: 17 yards + 2 feet + 5 inches Measuring things like this seems brain dead.
- kroltan 3y agoYes, it's a sample, like how sample programming code snippets use names such as Foo and Bar. Similarly braindead to do it in practice! Though imperial-system users don't mix units like that, it's not like "20 minutes 30 seconds", they just use fractions or decimals as appropriate. "20 and a half minutes" or "20.5 minutes". You'd just say "17.8 yards". (Metric user here, with an appreciation for base 12)
- jdmichal 3y agoI wish our number system was duodecimal. Then we probably would have ended up with base-12 metric, which would have been freaking awesome.
- kragen 3y agounits supports the dozenal system by default You have: QuedraTim You want: hour * 1 / 1 You have: QuedraTim You want: minutes * 60 / 0.016666667 You have: TrinaTim You want: minutes * 5 / 0.2 You have: DunaTim You want: minutes;seconds 25 seconds You have: QuenaTim You want: hour * 12 / 0.083333333 You have: Grafut You want: Definition: gravity Tim^2 = 0.29558045 m You have: QuedraGrafut You want: Definition: 12^4 Grafut = 6129.1562 m
- kragen 3y agoimperial system users totally do mix units like that: 5 feet 10 inches, two pounds and six ounces, nine stone and six pounds nobody has a tape measure marked in decimal yards or decimal feet, so nobody is going to say 17.8 feet or 17.8 yards sexagesimal system users also mix units like this: 2 hours, 10 minutes, and 5.2 seconds same for larger units of time: 5 years, 2 months, and 12 days (which is an example units(1) can't hack)
- teddyh 3y agoIIRC, 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.)
- beardog 3y agoThis is why I AGPL my projects even if i feel like it isn't likely to be used as a network backend.
- creatonez 3y agoWhat's nice about AGPL is that, as per Google's policy, it serves as an automatic ban from your software being used at Google, including non-networked applications like Android. Some people have said this is a downside or that Google's policy represents a red flag about the license itself, I see it as a good thing that the license makes them nervous.
- jonathankoren 3y agoMaybe the ripped out GNU Units. Never know, since they never distributed it.
- Shawnj2 3y agoIt’s also possible they fixed the bug in some other way that didn’t involve touching GNU Units, like using a different conversion program only for requests that could trigger the big.
- anonymousiam 3y agoYou have: 20 furlongs per fortnight You want: miles per hour * 0.0074404762 / 134.4 https://en.wikipedia.org/wiki/FFF_system https://en.wikipedia.org/wiki/FFF_system
- cycomanic 3y agoAt 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.
- kragen 3y agoYou have: dBm(40) You want: W * 10 / 0.1 also you can name the inverse with ~ You have: ~dBm(2 W + dBm(10)) You want: Definition: 33.031961 the man page documents these
- User23 3y agoWhat on Earth is an "aeginamina?"[1] [1] https://www.gnu.org/software/units/manual/units.html https://www.gnu.org/software/units/manual/units.html
- greenyoda 3y agoIt's an ancient unit of weight or currency. See the first answer on this page: https://www.reddit.com/r/commandline/comments/oy6xk5/units_cli_question/ https://www.reddit.com/r/commandline/comments/oy6xk5/units_c...
- alessmar 3y agoI also highly recommend checking out https://frinklang.org/ https://frinklang.org/
- EconomicsDense 3y ago[dead]
- roeles 3y agoSlightly 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.
- dredmorbius 3y agoGNU 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&query=500%20mile%20email&sort=byPopularity&type=story 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.
- yanosh_kunsh 3y agoI 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/ https://yanosh.net/units-wasm/ GitHub Repo for the demo: https://github.com/yanosh-k/units-wasm https://github.com/yanosh-k/units-wasm GitHub Repo for the WASM project: https://github.com/yanosh-k/gnu-wasmunits https://github.com/yanosh-k/gnu-wasmunits
- guidoism 3y agoWow I was just preparing to start this project myself. Before starting the process I did a last minute check and found this. Goes to show you that all you need to do is wait and someone will write the code for you. Thank you!
- cs3f16 3y agoIt would be nice to get implemented as an extension in VScode.
- bjoli 3y agoHaving used Emacs for most of my adult life, I find it pretty amazing that basic unit conversion isn't a part of every OS out there. I use it several times every week. I don't use the gnu units package though, I stay with the functionality built into Emacs calc.