Live data from Hacker News

GNU Units

gnu.org

101–110 of 117 posts

Re: GNU Units

#102
post #96

Earlier quoted context omitted.

Just 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++

I work in large C++ codebase for a suite of physics simulation software, and there are like 200 something strongly typed arithmetic units here.

Anything 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 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 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.

Re: GNU Units

#103
post #64

When 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.

Without looking into it at all, it probably just didn't have an active package maintainer.

The 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/2b5ec...

[1]: https://aur.archlinux.org/cgit/aur.git/commit/?h=units&id=e6...

[2]: https://archlinux.org/packages/?packager=arojas

Re: GNU Units

#104
Slightly 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.

Re: GNU Units

#105
post #77

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

Maybe the ripped out GNU Units. Never know, since they never distributed it.

It’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.

Re: GNU Units

#106

Earlier quoted context omitted.

Without looking into it at all, it probably just didn't have an active package maintainer.

The 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/2b5ec... [1]: https://aur.archlinux.org/cgit/aur.git/commit/?h=units&id=e6... [2]: https://archlinux.org/packages/?packager=ar…

Interesting! 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/

Re: GNU Units

#107
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…

Impressive list. The maintainers should copy paste this onto that page

Re: GNU Units

#108
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…

I use GNU Units a lot (and have mentioned it fairly frequently on HN -- 37 comments and one story submission: https://news.ycombinator.com/item?id=7297219>), and have for a couple of decades now, but not like this, despite what I consider to be some reasonably advanced conversions (e.g., https://news.ycombinator.com/item?id=8196590> & https://news.ycombinator.com/item?id=7606949>).

This is an absolutely awesome comment. Thanks, kragen.

Re: GNU Units

#109
GNU 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&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.

Post reply on HN