3 ms·
Does the Dimensional library work for weird units like Fahrenheit and Celsius (ie: where zero is in the wrong place)?
by xenomachina 13y ago
Does the Dimensional library work for weird units like Fahrenheit and Celsius (ie: where zero is in the wrong place)?
- jarrett 13y agoCelsius and Kelvin are supported. I'm not certain, but it would appear Fahrenheit support is not built-in. There's a module called NonSI: https://hackage.haskell.org/package/dimensional-0.13/docs/Numeric-Units-Dimensional-NonSI.html https://hackage.haskell.org/package/dimensional-0.13/docs/Nu... I would have expected Fahrenheit to be in that module if it were supported. But I presume you could add Fahrenheit yourself, if you were willing to learn a bit about the library's internals.
- nagisa 13y agoFahrenheit is not easily addable given current realisation of functionality and, if I recall correctly, somewhere in source code there’s a comment in which author explicitly states he doesn’t support units which don’t linearly correspond to SI-based unit.
- jimktrains2 13y agoThe function to convert Fahrenheit to Celsius is a linear function of C and K?
- cobbal 13y agoLinear in this case means y = m * x. The relationship between Fahrenheit and Celsius is affine (y = m * x + b) For gory details: https://en.wikipedia.org/wiki/Affine_transformation https://en.wikipedia.org/wiki/Affine_transformation
- judk 13y agoCelsius is an affine transformation of Kelvin
- jarrett 13y agoExactly, which makes me wonder why the library can support Celsius but not Fahrenheit. To say it in more detail: To transform between Celsius and Kelvin, you just translate. (That operation is supported in Dimensional.) To transform between Fahrenheit and Celsius or Fahrenheit and Kelvin, you translate and scale. We know that Dimensional can scale, because it supports things like miles to kilometers. We know it can translate, because it supports Celsius to Fahrenheit. Is it the combination of scaling and transforming that makes Fahrenheit impossible?
- jimktrains2 13y agomiles = constant * km though, you simply scale one to get the other. f = m*c + b, which is both a scale and a transform.
- jarrett 13y agoBut as stated above, Dimensional already does Celsius to Kelvin and vice-versa. Which is indeed of the form you just stated: f = m*c + b where m is simply equal to 1. Why wouldn't Fahrenheit conversion be the same thing, just with different constants?
- jimktrains2 12y agoMe no reed gud :-\ Yeah, you're correct.