13 ms·
GNU Units
- hprotagonist 6y ago> Like many similar programs, it can handle multiplicative scale changes. It can also handle nonlinear conversions such as Fahrenheit to Celsius how is C = (5/9)(F-32) not linear?
- oddeyed 6y agoIn certain contexts (such as linear algebra), linear refers to the fact that the mapping must cross the origin. This follows from the constraint that for a linear map f, f(a + b) = f(a) + f(b), which is not true for the farenheit-celsius example. EDIT: See https://en.wikipedia.org/wiki/Linear_function#As_a_linear_map https://en.wikipedia.org/wiki/Linear_function#As_a_linear_ma...
- jtanderson 6y agoAlso: a linear function plus a constant is said to be affine! Reference: https://mathworld.wolfram.com/AffineFunction.html https://mathworld.wolfram.com/AffineFunction.html
- phkahler 6y agoI just learned something. Is it correct to call both of the first order? Or is that term really only to be used for the underlying polynomials?
- dan-robertson 6y agoI think of nth order as mostly just applying to approximations. But I guess first order would be ok here.
- deleted 6y ago[deleted]
- olikas 6y agoIf f is linear, then f(a)=f(a+0)=f(a)+f(0). So f(0)=0.
- HourglassFR 6y agoBecause 0°C is not 0°F
- deleted 6y ago[deleted]
- SahAssar 6y agoAs I understood it: C to K would be linear since they are always offset by the same amount, but 0°C is not 0°K. C to F is not linear since they are not offset by the same amount.
- _0ffh 6y agoIt seems to me C to K is affine as well. True, it's somewhat special in that the factor is exactly one, but if there's an offset it's not linear in the sense of the sentence under discussion.
- dhosek 6y agoThat's not how it works. The definition of linear used in this context requires f(a+b) = f(a) + f(b) which is not the case with the C to K translation which is f(x) = x + 273.15 Only functions in the form y=mx+0 meet the criteria.
- wl 6y agoIt's affine. It's not linear because the offset means superposition doesn't hold.
- CyberRabbi 6y agoIt’s linear in terms of its order but it’s not a linear transformation, which must satisfy: f(c*(a+b)) = c*f(a) + c*f(b) Where c is a scalar. A and b are abstract objects. Examples include vectors, real numbers, and functions themselves.
- amelius 6y agoLinear does not mean "graph is a line". It means "graph is a line through origin" (in the 2d case). Somewhat counterintuitive, but that's how it's defined.
- diarrhea 6y agoThe Wikipedia article someone else posted already seems to disagree: https://en.wikipedia.org/wiki/Linear_function https://en.wikipedia.org/wiki/Linear_function. This confuses me.
- TeMPOraL 6y agoThe article actually agrees. > In mathematics, the term linear function refers to two distinct but related notions (...) [proceeds to specify them using incomprehensible math words] GNU Units documentation uses the second notion, common with linear algebra (and thus arguably more common in any computing) - the notion that calls y=ax a linear function, and y=ax+b an affine function.
- tait 6y agoSo, rather than calling it non-linear, which is clearly somewhat confusing, perhaps it would be more clear to state that it handles affine functions like F to C...?
- TeMPOraL 6y agoPerhaps. That's what I myself did when adding handling for affine unit conversions in a project I worked on.
- zeroimpl 6y agoAgreed. Why they wasting our time pointing out it’s “non-linear” when this statement is only true for some definitions of linear? Just pick a non-ambiguous word, or add an asterisk and footnote.
- mcguire 6y agoFrim jxy's 6th edition man page: "Units only does multiplicative scale changes. Thus it can convert Kelvin to Rankine, but not Centigrade to Fahrenheit."
- jhoechtl 6y agoIt's even in the documentation to Units: > But Fahrenheit to Celsius is linear, you insist. Not so. A transformation T is linear if T(x+y)=T(x)+T(y) and this fails for T(x)=ax+b . This transformation is affine, but not linear. https://www.gnu.org/software/units/manual/html_node/Overview.html#Overview https://www.gnu.org/software/units/manual/html_node/Overview...
- bjeds 6y agoHow does GNU Units compare to Frink ( https://frinklang.org/ https://frinklang.org/ )?
- deleted 6y ago[deleted]
- maxerickson 6y agoUnits is older, frink is a lot bigger, it's a whole programming environment. Frink started from and extended the units defined by Units, I don't know if anything has gone in the other direction. Later: for simpler calculations an interesting feature frink adds is the ability to do interval arithmetic. Terms can be specified as ranges that are then carried through the calculations to the result.
- jillesvangurp 6y agoLooks like it is comparable to javax.measure (https://jcp.org/en/jsr/detail?id=363 https://jcp.org/en/jsr/detail?id=363). I used an implementation of that a few years ago: https://github.com/unitsofmeasurement/uom-se https://github.com/unitsofmeasurement/uom-se It's a complex domain, especially if you get down to having more complex units composed of other units and want to do conversions between metric and imperial. In our case we were dealing with material properties (chemical, physical, magnetic, etc.) and different countries and companies using different ways to record characteristics for materials.
- samatman 6y agoThe author of Frink takes particular pride in doing unit maths correctly. For example, if the conversion between two units is defined by statute to be some weird ratio, Frink will use that, and not merely the best f64 approximation of that ratio. As indicated by a sibling comment, Frink also handles interval maths, and in general it just has a remarkable amount of features, being a fully-fledged programming language. It's a pity it isn't open-source, the author says he doesn't want the aggravation of having to deal with pull requests and so on, and just wants to work on his software project on his own. Which, ok, that's fair: but at least Lua and SQLite don't accept contributions from outside the team, so there's a model for releasing open-source software without having to collaborate with the general public. No question that it would increase the size of his inbox though, so I get it.
- BenjiWiebe 6y agoI love being able to convert from millilightseconds to miles, and vice versa. You can figure minimum latency for a given distance or maximum distance for a given latency.
- JadeNB 6y agoIs this a covert reference to the 500-mile e-mail?
- jeffcoat 6y agoProbably not. Knowing the speed-of-light round trip time to a network location gives you a bound on how much you can improve the performance of remote operations. For example, I'm in Austin, querying a database hosted in Amazon's us-east-1 data center ("Northern Virginia"). Call it 1000 miles away, 2000 mile round trip. You have: 2000 miles You want: millilightseconds 2000 miles = 10.736388 millilightseconds If I have a query that's taking < 1ms, no optimization of how that query is executed by the database can possibly improve the overall performance.
- ajsnigrutin 6y ago> You have: furlongs per fortnight We need to see this ^ more often in real life!
- ConceptJunkie 6y agoIt's a very slow velocity, though. It's best used for things like snails.
- ajsnigrutin 6y agoYou could count it in increments of some number, like 1280... so you'd have a car speedometer which would measure your speed in x*1280 furlongs/forthnight. (yes i'm joking, but considering all the other freedom units, and rules measuring in 1/64", it's not far from the truth)
- darkstarsys 6y agoI wish someone would make a spreadsheet that tracks units like this.
- alanbernstein 6y agoNot sure what you want in a spreadsheet, but the data is stored in text files. See https://www.gnu.org/software/units/manual/html_node/Units-Data-Files.html https://www.gnu.org/software/units/manual/html_node/Units-Da...
- netrus 6y agoNot sure what GP is thinking of, but type checking for Excel would be really nice: ERR: A1 is USD/month, B1 is USD/user, so you cannot calculate A1+B1!
- darkstarsys 6y agoNot the unit definitions in a spreadsheet; I'd like a spreadsheet where each cell has not just a number, but a number with its unit. Formulas would be evaluated the way `units` does it. B1=3m; B2=4s; B3="=B1/B2" would give as value of B3 "0.75 m/s".
- alanbernstein 6y agoAh, sure, that would be great. I'd say it would be useful in text based programming environments too though.
- protomyth 6y agoAgriculture would probably love a spreadsheet that understood units of measure and kept results as fractions. Gotta love that a bushel of Yellow Corn is a different weight than a bushel of Oats.
- mark-r 6y agoAll the grains are different. I had to hard code a table of those conversions for an application I worked on.
- Faaak 6y agoA simple example I used recently in order to guesstimate how much energy is needed to heat 300liters of water by 5K: You have: 5K * 300kg * water_specificheat You want: kWh * 1.7433333 really easy to use. How much power could you obtain with a small water turbine if you had 10m of head and 1l/s ? Easy ! You have: 10m * 1kg/s * gravity You want: W * 98.0665
- deleted 6y ago[deleted]
- FlyMoreRockets 6y agoI do these kind of calculations all of the time and never realize units had this level of functionality. Wow, thanks Faaak!
- zwog 6y agoThanks, I did not know that units is able to work with constants. I always used Insect[0] for this. 0: https://github.com/sharkdp/insect https://github.com/sharkdp/insect
- bombcar 6y agoI kept reading this as “water specific cheat” and was really confused.
- arthurcolle 6y ago~ units 586 units, 56 prefixes You have: 50m * 1kg/s * gravity unknown unit 'gravity' how did you get gravity?
- zouhair 6y ago$ units Currency exchange rates from FloatRates (USD base) on 2020-12-21 3677 units, 109 prefixes, 114 nonlinear units You have: 10m * 1kg/s * gravity You want: W * 98.0665 / 0.010197162 You have: You lack some units and prefixes.
- 6y ago
- amelius 6y agoWhy isn't this released as a library (as opposed to a program)?
- enriquto 6y agoA program is easier to use. You do not need to link to it, just run it! Do you have trouble running programs?
- macintux 6y agoPer another thread it sounds like Frink is what you want. https://frinklang.org/ https://frinklang.org/
- devenblake 6y agoIn the README in the GNU units source code (2.21): 203: Ideas the future (may or may not happen): 204: 205: * Bundle up the units conversion stuff into a library. At the end of units.c, too: 6280: /* NOTES: 6281: 6282: mymalloc, growbuffer and tryallunits are the only places with print 6283: statements that should (?) be removed to make a library. How can 6284: error reporting in these functions (memory allocation errors) be 6285: handled cleanly for a library implementation? 6286: 6287: Way to report the reduced form of the two operands of a sum when 6288: they are not conformable. 6289: 6290: Way to report the required domain when getting an domain error. 6291: 6292: */ My prowling of the source code is probably uninformed because I'm not a C expert by any means but it seems like you could include units.h and use many of the useful functions in another program.
- rubenbe 6y agoYou might also be interested in boost::units. It implements units using a ton of templates and "compile-time metaprogramming". [0] The nice thing is that it has no runtime overhead as all templates are "compiled away". The disadvantage is that when you make a mistake against units, it results in a "template compiler error explosion". [0]https://www.boost.org/doc/libs/1_65_0/doc/html/boost_units.html https://www.boost.org/doc/libs/1_65_0/doc/html/boost_units.h...
- enriquto 6y agoI love it, everything is there! You have: kilometers per hour You want: attoparsecs per microfortnight * 10.889018
- cmenge 6y agoThat's even better than the furlongs per fortnight example, which gave me a good laugh already :)
- Jedd 6y agoIt's a nod to the furlong-firkin-fortnight measurement system: https://en.wikipedia.org/wiki/FFF_system https://en.wikipedia.org/wiki/FFF_system
- dredmorbius 6y agoFor what's not, you can add additional definitions. I found myself wanting to calculate Little Boy blast yields sufficiently often that I added a hiroshimabomb unit of energy. Similarly, various areal units such as countries and states/provinces.
- edoceo 6y agoHow many Australian football fields in 1.3 Canada's?
- dredmorbius 6y agoAussie Rules is a variably-specified pitch: Australian rules football grounds, even at the highest level of the game, have no fixed dimensions. For senior football, the playing field is an oval, typically between 135–185 metres (148–202 yd) long goal-to-goal and 110–155 metres (120–170 yd) wide wing-to-wing. Grounds can vary from long and narrow to almost circular, and are not necessarily symmetrical, depending upon how and where the field was constructed. At least 5 metres (5.5 yd) of space between the boundary line and any fence is required for safety. https://en.wikipedia.org/wiki/Australian_rules_football_playing_field https://en.wikipedia.org/wiki/Australian_rules_football_play... Canadian Football: 150 yards length overall, 65 yards width overall. 2.0144628 acres area, 0.81522418 hectares. https://sportsknowhow.com/football/field-dimensions/canadian-cfl-football-field-dimensions.html https://sportsknowhow.com/football/field-dimensions/canadian... The other question is if you're looking for length or areal metrics.
- johnisgood 6y agoGNU Units is a beautiful piece of software. I keep using it for everything. You can convert between currencies, too. If GNU Units cannot do something, I resort to using Maxima[1]. [1] https://maxima.sourceforge.io https://maxima.sourceforge.io
- Ajedi32 6y agoI've been using WolframAlpha for this sort of thing. The idea of using something fully local and open-source does have some appeal, but it's hard to compete with the convenience of Ctrl+T "wo" <Tab> <Query> <Enter>.
- TeMPOraL 6y agoYou mean Ctrl+T "wo" <Tab> <Query> <Enter> <Wait 15 to 60 seconds for the page with your results to load> <Get something that's a mighty pain to copy/paste from>. This experience is why I stopped using W|A few years ago. It's awesome, but it's also a pain.
- Ajedi32 6y agoCan relate; that's definitely been an issue for me as well. Though on the plus side it's nice to be able to open multiple tabs, make small tweaks to the formula, and switch between them to compare results. Kinda wish there was an open source browser-based WolframAlpha alternative which did more of the computation locally so everything wasn't so slow.
- pbhjpbhj 6y agoI used to love Wolfram Alpha but it hasn't worked for me for several years and I've been unable to find out why. Just tested now and it does work on Android FF - yay! But not on my desktop (neither Chrome nor Edge). Doesn't work for me on Firefox nor Brave either (neither Win10 nor Kubuntu). I have randomly assigned IP from major UK provider (which provider has also changed). Doesn't work through my work VPN either. I've taken to using Geogebra (online) when I quickly need a function plotting.
- 6y ago
- gquiniou 6y agoDoes the GNU projet make its repositories available online ? I'd like to have a look at the code but all I found is an outdated mirror : https://github.com/ryantenney/gnu-units https://github.com/ryantenney/gnu-units
- notRobot 6y agoHere you go: http://savannah.gnu.org/projects/units http://savannah.gnu.org/projects/units All official GNU software is hosted here: http://savannah.gnu.org http://savannah.gnu.org
- wheybags 6y agoGNU Savannah is where they keep their source IIRC. https://savannah.gnu.org/projects/units https://savannah.gnu.org/projects/units Unfortunately it looks like the upstream for this project is in... cvs
- kps 6y agoFor comparison, the original: https://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/units.c https://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd... (Slightly discombobulating to read some of today's lucky 10,000 treating `units` as a (GNU) novelty when it's been around for 40+ years.)
- bodyfour 6y agoOr if you'd rather see it in git https://github.com/dspinellis/unix-history-repo/blob/BSD-4-Snapshot-Development/.ref-BSD-3/usr/src/cmd/units.c https://github.com/dspinellis/unix-history-repo/blob/BSD-4-S...
- kumarsw 6y agoLooks cool. If the poster is affiliated with the project, some suggestions: 1. I don't know what I am looking at with the examples. I think that this is an interactive session with the program, but this is not clear. 2. It is also unclear how to start the program as the executable name is not specified. This and the former point could be addressed by including one of those gifs of an interactive session that are popular in GitHub readmes these days. Sure, they are a bit gimmicky, but still useful. 3. It is not clearly stated if this is an executable program or a library. I believe it is the former, but this is nowhere in the introduction. 4. Probably this is included with a number of package managers. If that is the case, instructions for installing via a package manager would be helpful, especially since the name is not particularly unique.
- c22 6y agoThere's a link to the documentation [0] right on the page. The documentation is very clear. People should read their package manager's documentation for help using their package manager. [0] https://www.gnu.org/software/units/manual/units.html https://www.gnu.org/software/units/manual/units.html
- kumarsw 6y agoI agree with you, but package names aren't predictable. I find that an example of installing a package is helpful even for users familiar with use of package managers as it gives context and helps readability. Whenever I see `sudo apt-get somethingsomething` I immediately know that somethingsomething is the package name.
- typhonius 6y agoMy first exposure to GNU Units was when I read the story about emails failing if they were to be sent more than 500 miles. I’m sure it’s popped up here before but here’s a link for those who haven’t come across it: https://www.ibiblio.org/harris/500milemail.html https://www.ibiblio.org/harris/500milemail.html
- lozf 6y agoSame here back in the early aughts, but it took me a while to really dig in and discover that units also handles times too. e.g. units "sec $(echo $SECONDS)" "day;hr;min;sec"
- philjackson 6y agoUseless use of echo there.
- ttul 6y agoNot unless you’re also trying to demonstrate the magic of fork.
- lozf 6y agonoted, thanks
- techbio 6y agoExtraneously strenuous use of "useless" when using "redundant" would have done...unless useless has another usage. EDIT: The commenter echoed, duckly.
- x0 6y agoIt's very important to watch out for useless uses of echo/cat. What is cat, a few megabytes now? Fine for those of us on modern hardware, but you never know what PDP-11 user is going to copy paste your comment into their terminal.
- watersb 6y agoI use a construct like this to ensure that the value ends with a newline.
- tunnuz 6y agoLove it!
- Symbiote 6y agoI started using this tool some years ago after I found out the CO₂ cost of a Google search. I don't need a web query when I search "40000lb in tonnes" when reading an American news article, for example. units 40000lb tonnes * 18.143695 It even includes currencies. "sudo units_cur" will update the exchange rate data file, if you need that. units 50GBP USD * 68.143948
- Freak_NL 6y ago> "sudo units_cur" will update the exchange rate data file, if you need that. Oh good tip that. I noticed the package on Ubuntu 20.04 came with currency conversion from 2019. Not very useful without updating it.
- skissane 6y ago> It even includes currencies. "sudo units_cur" will update the exchange rate data file, if you need that. Doesn't work for XDR. Of course, who needs XDR? I sure don't. But you can get the XDR exchange rate with this command: curl -d '__EVENTTARGET=lbnTSV' POST -v https://www.imf.org/external/np/fin/data/rms_sdrv.aspx https://www.imf.org/external/np/fin/data/rms_sdrv.aspx Maybe someone should integrate that into units_cur.
- visviva 6y agoI absolutely adore this program. It works exactly like I expect, every time. Sometimes I'll just think about what a nice tool it is, even when I'm not using it.
- IfOnlyYouKnew 6y agoMy go-to test for such systems is converting miles per gallon to liters per 100 km. Can anybody give it a try? Google did it well for the longest time, then stopped at some point. Now it works again. Just tried it on iOS and it works now. Don’t quite remember when I last tried, but I believe it’s fairly recent.
- deleted 6y ago[deleted]
- deleted 6y ago[deleted]
- Rygian 6y ago$ units "6 l/100 km" mpg reciprocal conversion * 39.202431 / 0.025508622
- bentcorner 6y agounits "30 miles per gallon" "liters per 100km" reciprocal conversion * 7.8404861 / 0.12754311
- Symbiote 6y agoWhat I particularly like is the use of the locale: LANG=en_GB.UTF-8 units "30 miles per gallon" "liters per 100km" reciprocal conversion * 9.4160312 / 0.10620186 LANG=en_US.UTF-8 units "30 miles per gallon" "liters per 100km" reciprocal conversion * 7.8404861 / 0.12754311 (Although it is incomplete, as it only uses Imperial gallons for "gallon" for en_GB, although there are probably more English locales that use(d) the Imperial gallon than the US gallon.)
- nemetroid 6y agoFor Python, I've had good experience with the Pint library[1]. It's helped avoid a whole class of bugs. 1: https://pint.readthedocs.io/en/stable/ https://pint.readthedocs.io/en/stable/
- tsujp 6y agoI keep using different tools to do conversions so now I can unify that all into Units and get my speed in furlongs per fortnight as the ancient prophecies foretold. Rejoice! (but for real this is top I’m replacing multiple other tools with Units)
- FnuGk 6y agoYou have: 1 kelvin You want: degcelsius * 1 / 1 This does not seem right
- dagw 6y agoIt's right in the sense that the units are the same size. IE if something increases 10 deg K it also increases 10 deg C. But it's obvious to humans that that isn't what you where asking. Compare: You have: 1 degF You want: degcelsius * 0.55555556 / 1.8
- tialaramex 6y agoNitpick: There are no "deg K", because it is an absolute system it doesn't have degrees. Notice you also don't need degrees metre, degrees watt or degrees newton, because those are absolute units they are metres, watts and newtons. It is Celsius (and Fahrenheit) which are weird because they aren't absolute but instead have this arbitrary zero point.
- TurkTurkleton 6y agoIt is. The unit Kelvin is equal to the degree Celsius. If you want to convert temperatures, you need to use tempK and tempC: You have: tempK(1) You want: tempC -272.15
- boogies 6y agohttps://www.gnu.org/software/units/manual/units.html#Temperature-Conversions https://www.gnu.org/software/units/manual/units.html#Tempera... > Conversions between temperatures are different from linear conversions between temperature increments—see the example below. The absolute temperature conversions are handled by units starting with ‘temp’, and you must use functional notation. The temperature-increment conversions are done using units starting with ‘deg’ and they do not require functional notation.
- deleted 6y ago[deleted]
- LordHeini 6y ago
- nousermane 6y agoDo GNU Units handle units with implicit parameters? For example, 1500 mAh (milliamp∗hours) could be converted to 5.55 Wh (watt∗hours), or 19.98 kJ in SI units, in the context of a 3.7-volt battery. Naive approach fails: $ units "1500 milliampere*hours at 3.7 volts" "watt*hours" conformability error 1.9593687e+09 kg^2 m / s^4 3600 kg m^2 / s^2
- johnisgood 6y agoYou have: 1500 mA * hr * 3.7 V You want: kJ * 19.98 / 0.05005005 You have: 1500 mA * hr * 3.7 V You want: watt * hours * 5.55 / 0.18018018
- fanf2 6y agoYou are multiplying mAh, volts, and atmospheres. (“at” is a unit not an operator.) You want to just multiply mAh and V like You have: 1500 mA hours * 3.7V You want: W hours * 5.55 / 0.18018018
- sls 6y agoYou have: 1500 mA * hours * 3.7 V You want: watt * hours * 5.55 / 0.18018018
- oblio 6y ago> You have: 1|6 cup Is that a pipe for division?
- fanf2 6y agoIt has both / for division with the usual precedence and | for very tight-binding division, for use in fractions. So 1/6 cup parses as 1/(6 cup) but 1|6 cup parses as (1/6) cup.
- kazinator 6y ago> nonlinear conversions such as Fahrenheit to Celsius The heck? "y = ax + b" is linear; just not homogeneous linear. https://en.wikipedia.org/wiki/Fahrenheit#Definition_and_conversion https://en.wikipedia.org/wiki/Fahrenheit#Definition_and_conv... https://en.wikipedia.org/wiki/Homogeneous_function https://en.wikipedia.org/wiki/Homogeneous_function
- contravariant 6y agoIt's not a linear function for what it's worth. It breaks the f(x + y) = f(x) + f(y) part of linearity. It is a linear equation, confusingly enough.
- kazinator 6y agoThat's linear in the sense of "linear operator" or "linear map". I've never heard "nonlinear" as the opposite of that due to to a constant offset. "Linear map" and "linear operator" are used in contexts where homogeneity is a given. A scaling plus displacement is linear in the sense of "linear equation" because, for instance, if you scale a signal and add DC offset, there is no distortion; no new harmonics are present in the output signal. ax + by + c is called linear because the plot of points which satisfy the equation form a straight line; there is nothing confusing about it whatsoever. Temperature delta conversions between C and F are certainly a linear map/operator. If it gets 5°C hotter, and then 3°C hotter, making 8°C hotter, that's exactly like 9°F hotter plus 5.4°F hotter making 14.4°F hotter. Here is a test for linearity for a real-valued one-argument function which is not confused by an offset: x + y f(x) + f(y) f( ------ ) = ----------- 2 2 Works just fine for °C/°F. There is another criterion for a linear map that hasn't been mentioned, though: f(ax) = af(x).
- contravariant 6y agoWell one way or another it's not a linear function, so calling it a non-linear conversion is technically not incorrect. That said I completely agree that it makes way more sense to just call it a linear conversion and to pick an example that's truly nonlinear. Not that there are that many non-linear units, but something like decibel or beaufort might work.
- jxy 6y agoIt's not about GNU. V6 Unix (circa 1975) had it: http://man.cat-v.org/unix-6th/6/units http://man.cat-v.org/unix-6th/6/units Your macOS have the BSD version: % units -v units version 1.0 Copyright (c) 1993 by Adrian Mariano This program may be freely distributed usage: units [-f unitsfile] [-q] [-v] [from-unit to-unit]
- boomboomsubban 6y agoI'm not sure of the total history, but "by Adrian Mariano" means macOS uses GNU units. Wiki says they forked a copy before the license change.
- jxy 6y agoYou are probably right. The one in FreeBSD is from NetBSD: https://svnweb.freebsd.org/base/head/usr.bin/units/units.c?view=log https://svnweb.freebsd.org/base/head/usr.bin/units/units.c?v... The NetBSD version is from Adrian Mariano: http://cvsweb.netbsd.org/bsdweb.cgi/src/usr.bin/units/units.c?only_with_tag=MAIN http://cvsweb.netbsd.org/bsdweb.cgi/src/usr.bin/units/units.... The one in Plan9 is in yacc: http://9p.io/sources/plan9/sys/src/cmd/units.y http://9p.io/sources/plan9/sys/src/cmd/units.y This GitHub repo claims to be V6: https://github.com/memnoth/unix-v6/blob/master/source/s2/units.c https://github.com/memnoth/unix-v6/blob/master/source/s2/uni...
- boogies 6y agoIt’s about Unix, and GNU’s Not happens to be the best implementation of it. Which is why macOS copies pieces of it, despite needing to use obsolete versions in order to comply with Apple’s hatred for end-user freedom.
- derefr 6y agoI’ve always wondered why units(1) isn’t a library. I’d love to have access to abstract “united quantities” and “united measurements” in my HLL of choice, rather than needing to switch to a special-purpose tool (units, Frink) or a statistical-analysis language like R just to get them. Sometimes I need to bust out stoichiometry-like unit-balancing in the middle of my code, and I want type enforcement that I’m getting the right units in the output! Sometimes I want to do a series of floating-point calculations, and I need to put error-bars on the result, and it’d be great if those were tracked for me in the form of a measurement ADT that tracked sig-figs. Etc. My only guess for why there’s no libunits, is that it’d be a obtrusive black-box of operational non-guarantees if it was implemented in C, given that what Units does — if naively implemented — would be heavy on arbitrary memory allocations, and basically necessitate garbage collection. It’d make much more sense for a libunits to exist as a C++-ish “template library” that takes an allocator as an argument; but that doesn’t really help anyone who wants to use any language other than C++ (as the template parameters can’t be exposed in the C wrapper code that other languages FFI to.) (Before someone asks, you could get a limited kind of united-quantities — ones that can only represent “realistic” units — with a static per-qty bitfield representing the compiled-in units. But this wouldn’t really let you represent arbitrary unexpected “unit polynomial” qtys, e.g. m^5s^-3. This might seem fine, but sometimes intermediate quantities in formulae look like that, even though they work out to something sensible when everything is multiplied out.) Even if there couldn’t be a single units library implementation, it’d at least make sense for there to be 1. a canonical libunits-data release (sort of like tzdata), that individual library impls could pull in; and 2. a high-level API spec or reference-impl of what a libunits library for a given language-runtime would look like (sort of like how every HLL has copied JodaTime’s datetime design.)
- MawKKe 6y agoFYI: use tab completion in the 'units' REPL to show a list of available definitions. You won't find them in the 'units' manpage, as they are defined in an external datafile (on my machine this file is /usr/share/units/definitions.units)
- LeonM 6y agoThe documentation seems a bit incomplete, not what I'm used to with GNU. There seems to be no list of all units supported. I tried converting torque "100 ft lbf" to standard ISO notation (Nm). Let's see: units "100 ft lbs" "Nm" > Unknown unit 'Nm' units "100 ft lbs" "nm" > conformability error units "100 ft lbs" "newton meter" > * 135.58 How am I supposed to know that 'newton' must be written in full (though 'ft' and 'lbs' can be abbreviated)? Searching for 'newton' in the manpage yields 0 results.
- kps 6y agoThe list of all units supported is, for the GNU version, /usr/share/units/definitions.units
- messe 6y agoIt should be “N m”, even standard ISO notation requires a small space between the two.
- db48x 6y agoThe supported units aren't listed in the man page, because they're defined in a data file. Your site might have customized that file, meaning the man page would be incomplete.
- wscott 6y agoI typically use google for most unit conversions. How much concrete do I need for my driveway? I type this at the top of Chrome: 1/4 mile * 8ft * 4in in yd^3
- Cerium 6y agoMy favorite Google unit query: "the speed of light in ghz*in". The answer is the interesting and useful 11.8028527. Interesting because if you have not studied microwaves, you might not even know that as a unit for the speed of light, useful because it makes clear the relationship between wavelength and antenna length. Divide to cancel frequently and you have wavelength.
- mark-r 6y agoGrace Hopper used to give talks and hand out 11.8 inch pieces of wire, calling them nanoseconds. https://en.wikipedia.org/wiki/Grace_Hopper#Anecdotes https://en.wikipedia.org/wiki/Grace_Hopper#Anecdotes
- Cerium 6y agoThanks for sharing, I had never heard this before.
- ConceptJunkie 6y agoThis is the same as inches per nanosecond, which is a little more intuitive for us non-antenna-designers.
- wscott 6y agoMy hp48 calculator had unit conversions built-in. You could add units to any number and then conversions are done automatically when you do math: (1_ft + 1_in) / 20_s + 5_mi/h if the units don't match then the operation was an error: 1_ft + 1_gal => error As other people have mentioned I really wish spreadsheets had this built-in where units are like formats for a cell. Ii controls about how you want things displayed and will prevent you from making conversion mistakes or doing illegal operations.
- groks 6y agoEmacs has org-mode, and org-mode has tables with formulas which can invoke calc-mode. calc-mode also has units: https://www.gnu.org/software/emacs/manual/html_node/calc/Units.html#Units https://www.gnu.org/software/emacs/manual/html_node/calc/Uni...
- sequoia 6y agoI must be dense but what do the star and the slash mean? It looks like "multiply by" and "divide by" but it appears to have results of the conversion next to the star... Do the docs explain this and I missed it? You have: 1 lbs You want: kg * 0.45359237 / 2.2046226 You have: 2 lbs You want: kg * 0.90718474 / 1.1023113 You have: 2.4 lbs You want: kg * 1.0886217 / 0.91859276
- yrro 6y agoIt's in the manual: https://www.gnu.org/software/units/manual/html_node/Interactive-Use.html#Interactive-Use https://www.gnu.org/software/units/manual/html_node/Interact... "The second number gives the conversion in the opposite direction." Try with 'units --verbose' and you get nicer output: $ units lb kg lb = 0.45359237 kg lb = (1 / 2.2046226) kg
- deleted 6y ago[deleted]
- djur 6y agoIt's just showing the inverse. It makes more sense if you don't enter a number for the first unit: You have: kg/day You want: lb/hr * 0.091859276 / 10.886217
- wcoenen 6y agoFor the non-unix folk: I regularly use wolframalpha.com for similar things. Example query to estimate how much electricity bitcoin miners can afford to use at current prices: https://www.wolframalpha.com/input/?i=%28%286.25+bitcoin+%2F+10+minutes%29+%2F+0.05+dollar%2Fkwh%29+as+a+percentage+of+world+electricity+consumption https://www.wolframalpha.com/input/?i=%28%286.25+bitcoin+%2F...
- acidburnNSA 6y agoGNU units works great on windows. Install with chocolatey or directly with gnuwin. It's a bit outdated, but works for most things just fine. https://chocolatey.org/packages/GnuWin/0.6.3 https://chocolatey.org/packages/GnuWin/0.6.3
- liminal 6y agoUnits should be built into languages! Others have pointed to some libraries that make this possible in C++ and Rust; I'm sure it exists for other languages too. But this seems still short of what's needed: Every number in an application should be of a certain type and those types should combine on mathematical operations. Often those types already exist within the application's type model -- i.e. every class/interface is an obvious candidate. Then it would just be a matter of assigning those types to numbers. This would yield the ability to express things like Users/Client or Requests/second through simple math operations on variables and have it all type checked.
- fuball63 6y agoAda does this well with its concept of subtypes; so you could subtype Int to your unit, and even give it valid ranges. It's then typechecked by the compiler.
- db48x 6y agoIt's a lot harder to do well than it looks, mostly because unit systems were invented by humans and have a lot of aggravating edge cases and oddities. For example, most units can be converted to another unit of the same dimensionality by mulitiplication or division (such as length in inches * 2.54 == length in millimeters), but then there's temperature where you also need to add or subtract an offset. It's almost as if humans spent thousands of years inventing units without ever once considering how difficult they might be to implement in a computer programming language.
- Symbiote 6y agoAre there any edge cases if we just stick to SI units? Most of the world doesn't care about the thousand-year units, and the bit that does could just convert to them on output.
- db48x 6y agoTemperature, times, dates, cgs vs mks, dimensionless quantities, angles, the list goes on and on. And that’s before you get into the technical details of how you store units and conversion factors in memory, how you handle precision when mixing large and small units, how you interact with unlimited‐precision and rational numbers, how you use or avoid the type system in your programming language, how users of your unit library define their own units… Here’s a good write‐up of what they’re thinking about for future versions of C++: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1935r2.html http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p193.... It’s worth a read even if you don’t write in C++. And if you bake it into your language, you’d better get it all right the first time, because you probably won’t be able to fix it later.
- benibela 6y agoI have been using qalc for that How does it compare? $ qalc > furlongs per fortnight furlong / fortnight = 1 fur / fortnight > to m/s 1 fur / fortnight = approx. 0,0001663095238 m / s > 17 yards + 2 feet + 5 inches (17 * yard) + (2 * foot) + (5 * inch) = 17 yd + 2 ft + 5 in > to meter 17 yd + 2 ft + 5 in = 16,2814 m >
- JNRowe 6y agoFor use cases like that it is incredibly similar if you give the --verbose flag: $ units --verbose [header] You have: furlongs per fortnight You want: m/s furlongs per fortnight = 0.00016630952 m/s furlongs per fortnight = (1 / 6012.8848) m/s You have: 17 yards + 2 feet + 5 inches You want: meter 17 yards + 2 feet + 5 inches = 16.2814 meter 17 yards + 2 feet + 5 inches = (1 / 0.06141978) meter Personally, I find qalc via qalculate-gtk more useful for exploratory sessions but I still use units an awful lot.
- danaliv 6y agoOh thank goodness, I can stop using Google for this. (Aside: Is anyone else annoyed that Google doesn't understand what a hectopascal is? It interprets hPa as Pa, which is obnoxious. Every time I convert to or from hPa I have to do it twice: once in hPa and then again in millibars.)
- YesThatTom2 6y agoThe units command has been part of Unix since the 1970s. GNU Units is a clone with many improvements and has been around since the 1980s. You kids gotta learn your damn history!
- danaliv 6y agoIn my defense, I've been using Unix since the early '90s (was taught Scheme and C on a DEC ULTRIX, and then got my hands on a Turbo NeXTstation). This is a rare gap in my knowledge. ;-)
- YesThatTom2 6y agoI forgive you.
- gwbas1c 6y agoIMO, a port to a browser or mobile app makes a lot of sense.
- annoyingnoob 6y agoCame to say the same. Free and quality mobile apps without ads are sorely lacking. Obviously there are some stark philosophical differences between GNU and the walled gardens of mobile devices. But users don't care about that, they just want good software.
- dredmorbius 6y agoA favourite tool, which I also found via Trey Harris's speed-of-light email post. I've written a few quick guides and examples using GNU units: GNU 'units' utility and energy / resource calculations https://old.reddit.com/r/dredmorbius/comments/1x9u0f/gnu_units_utility_and_energy_resource_calculations/ https://old.reddit.com/r/dredmorbius/comments/1x9u0f/gnu_uni... How many Hiroshima bombs in a Ferrari, with mass-energy conversion (or how I learned to extend GNU units) https://old.reddit.com/r/dredmorbius/comments/1yvxde/how_many_hiroshima_bombs_in_a_ferrari_with/ https://old.reddit.com/r/dredmorbius/comments/1yvxde/how_man... And for assessing specifc alternative energy claims: Boeing's Biofuel "Breakthrough" -- Less than overwhelming https://old.reddit.com/r/dredmorbius/comments/1wo2hl/boeings_biofuel_breakthrough_less_than/ https://old.reddit.com/r/dredmorbius/comments/1wo2hl/boeings...
- singularity2001 6y agoI think I'm using it incorrectly: ./units "3 km in miles" Definition: 122632.01 m^3
- mssdvd 6y agoTry: units 3km miles
- Symbiote 6y ago"in" is the abbreviation for inches, and school maths/physics class taught us that length × length × length = volume, which is exactly what you have: 3 kilometres × 1 inch × 1 mile. My physics lessons at secondary school must have spent at least a week on SI units, base and derived units: Force = mass × acceleration N = kg × m·s¯² (i.e. a Newton is a kilogram-metre-per-second-squared.) Pressure = force ÷ area Pa = N ÷ m² Pa = kg·m·s¯² ÷ m² Pa = m¯¹·kg·s¯² (So Pascals are Newtons-per-square-metre, or kilograms-per-metre-per-second-squared.)
- adrianmonk 6y agoI recommend the "-1" (also called "--one-line") flag for bc. It takes away the extra (to me) reciprocal conversion factors. (Note: it's the number one, not a lowercase "L".) Without: $ units Currency exchange rates from FloatRates (USD base) on 2019-05-31 3460 units, 109 prefixes, 109 nonlinear units You have: inch You want: cm * 2.54 / 0.39370079 You have: With: $ units -1 Currency exchange rates from FloatRates (USD base) on 2019-05-31 3460 units, 109 prefixes, 109 nonlinear units You have: inch You want: cm * 2.54 You have: To me the reciprocals are just clutter. If I want a reciprocal, I will just type the two parts of my query in the opposite order. I'd even say they're confusing because you have to look at them understand why there are two numbers. (Also on the subject of flags, I'd like one that suppresses the first two lines of output but not the prompts like "You have:".)
- scaladev 6y agoDid you paste that printout from a recent run of units? If so, the currency rates are pretty useless. You can configure the system to update them daily (or however you like) with something like this: $ cat /etc/systemd/system/units-currency-update.service [Unit] Description=Update units(1) currency rates [Service] Type=oneshot Nice=19 ExecStart=/usr/bin/units_cur $ cat /etc/systemd/system/units-currency-update.timer [Unit] Description=Update units(1) currency rates [Timer] OnCalendar=daily AccuracySec=3h RandomizedDelaySec=3h Persistent=true [Install] WantedBy=timers.target # systemctl daemon-reload # systemctl enable units-currency-update.timer
- boogies 6y agoOr just something like 0 0 * * * nice -n 19 /usr/bin/units_cur for *BSD crontabs or both HN users (besides me) who prefer systemd-free distros of GNU
- adrianmonk 6y agoCorrections (b/c too late to edit): (1) The flag isn't for bc, of course; it's for units. I'm always running the wrong one, so no surprise I mixed them up again. (2) Should read "look at them to understand" near the end.
- m463 6y agoI use units all the time on macos. I don't know how it derives/compares to the gnu version $ units -v units version 1.0 Copyright (c) 1993 by Adrian Mariano This program may be freely distributed It doesn't do temperature (which would make it more useful)
- bwasti 6y ago> It can also handle nonlinear conversions such as Fahrenheit to Celsius huh?
- every 6y agoMy favorite units conversion is smoots per furlong...
- DreamScatter 6y agoRecently I created a library for unit conversion in Julia, which is the most complete tool for unit conversion I am currently aware of https://github.com/chakravala/UnitSystems.jl https://github.com/chakravala/UnitSystems.jl
- darkstarsys 6y agoCool, so my phone has a 69.6 btu battery. % units --verbose -1 '4080mA hours * 5V' btu 4080mA hours * 5V = 69.607689 btu
- garfieldnate 6y ago>You have: 7 meters >You want: ft;in > 22 ft + 11.590551 in Is there a way to get inches in ruler-based fractions instead of decimals? Imperial rulers don't give you tenths or hundredths of an inch, so I would find it much more useful if the output were "just under 22ft + 11 19/32in" or something similar.