Live data from Hacker News

GNU Units

gnu.org

71–80 of 117 posts

Re: GNU Units

#71

> You have: 17 yards + 2 feet + 5 inches Measuring things like this seems brain dead.

Measuring is a highly subjective and personal experience in general.

As a physics undergrad I had a fascinating discussion with a lecturer on metrology. I always used SI units, my friend always preferred natural units, and the lecturer used gaussian units frequently (which always threw me off).

My position was that SI is the only reasonable measuring system because it’s a widely accepted standard, has no silly conversions, and bears resemblance to things we experience in every day life. I can space my hands apart by a metre through guesswork and I’m generally quite close, but centimetres or inches I’m awful at (any excuse, eh?). I can judge how many kilograms something is but not grams or pounds.

“Ah,” said the lecturer. “But these are units you are familiar with because they match your everyday experiences. In mine, statVolts etc are the most natural thing in the world - I don’t have constants where I don’t need them, and my numerical results are at a comfortable order of magnitude”.

“The most natural thing in the world are the universal constants - planck’s constant, the speed of light, the charge on an electron”, countered my friend. “If I measured something in those, anyone or anything in the universe, under any physical conditions, can recreate my measurements. If civilisation ended and my calculations were discovered millions of years later by an entirely new intelligent species, they would understand it with enough legwork”.

I quickly became a proponent of natural units. But then 50mph signs being renamed to 7.46e-8 might not go down well with the highways agency.

Anyway, the point of this story is that measurements are measurements, as long as they’re consistent. It isn’t about intellect, it’s about what you’re working with, what you normally work with, culture, and all kinds of things. If you have a 17 yard thingamagig and need 2ft clearance on one side and 5in clearance in the other, then this is a perfectly reasonable task to ask a computer with a teraflop or so of computational power.

Re: GNU Units

#72

(2016) Posted a few times recently Here's some more discussion 3 years ago: https://news.ycombinator.com/item?id=25657311

It's not (2016) in my opinion - this page was last updated then, but the most recent release of the software was in 2022.

If we’re going by age of article, (1997) is probably closer:

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.

Re: GNU Units

#73
post #63
post #6

Earlier quoted context omitted.

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

That still requires you to know about its existence. It's perfectly possible to write F# code without those and messing up units conversion.

Someone 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 
GHC will give you an error because `speed3` is mistyped.

[1] https://hackage.haskell.org/package/dimensional

Re: GNU Units

#74
post #43

ah, so that's how you do °C / °F ... You have: tempF(45) You want: tempC 7.2222222

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

Re: GNU Units

#75
post #7

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

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

> units comparison and conversions even on C++

See mp-units[1].

[1]: https://github.com/mpusz/mp-units

Re: GNU Units

#76

Earlier quoted context omitted.

Then how do you deal with non-SI units, like money?

You can't really convert units of money to any other units, so I'm not convinced of the utility of money conversion in this kind of tool. US Dollars would be connected to US Cents in the graph, and Pounds Sterling and New Pence would be connected to each other too, but those two subgraphs would be entirely disconnected from each other and from any SI unit like distance or mass.

It's useful for some practical conversions like fuel efficiency calculations. I think in USD per mile and it's handy to be able to directly take CAD/liter and l/km for my trips to Canada.

Re: GNU Units

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

Re: GNU Units

#78
post #43

ah, so that's how you do °C / °F ... You have: tempF(45) You want: tempC 7.2222222

I use this daily eg.

  temp 42F
or

  temp 39C

  #!/bin/sh

  if echo "$1" | grep -q '[0-9][0-9]*[fF]' ; then
     val=`units "tempF( $(echo $1 | sed 's/[a-zA-Z]//g') )" tempC`
     echo ${val}C
  else
     val=`units "tempC( $(echo $1 | sed 's/[a-zA-Z]//g') )" tempF`
     echo ${val}F
  fi

  exit 0

Re: GNU Units

#79
post #74
post #43

ah, so that's how you do °C / °F ... You have: tempF(45) You want: tempC 7.2222222

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

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

Re: GNU Units

#80
post #68

> You have: 17 yards + 2 feet + 5 inches Measuring things like this seems brain dead.

Yes, 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)

I wish our number system was duodecimal. Then we probably would have ended up with base-12 metric, which would have been freaking awesome.
Post reply on HN