convert-units icon indicating copy to clipboard operation
convert-units copied to clipboard

negative temperatures

Open mzihlmann opened this issue 3 years ago • 5 comments

First of all, thank you for that great library, it would be a real headache without.

im currently running 3.0.0-beta.3, because this way i get the toBest() function.

what i run into currently is the way negative temperatures are treated. Any negative temperature will be shown in Kelvin and Rankine respectively, which is a choice. But for my not scientific users it would be better to show small negative temperatures in C and F.

convert(-5).from('C').toBest({system: 'metric'}) // 268.15 K
convert(-5).from('C').toBest({system: 'imperial'}) // 23 F
convert(-20).from('C').toBest({system: 'imperial'}) // 455.67 R

So i thought i can quickly override that choice and exclude Kelvin and Rankine when something unexpected happened

convert(-5).from('C').toBest({system: 'metric', exclude: ['K', 'R']}) // null
convert(-5).from('C').toBest({system: 'imperial', exclude: ['K', 'R']}) // 23 F
convert(-20).from('C').toBest({system: 'imperial', exclude: ['K', 'R']}) // null

I would expect the conversion to fallback to C and F respectively instead.

mzihlmann avatar Mar 30 '22 11:03 mzihlmann

Thanks for taking to time to create this issue. I think this is related to #152. I plan on spending some time looking into this issue in the near future. If you are able to provide any other examples of were toBest does unexpected things, that would be much appreciated.

Taar avatar Mar 30 '22 17:03 Taar

There is one issue with the toBestmethod that isn't an easy fix, due to the fact that the best value is subjective. And in the case of temperatures, there isn't really a better representation of -5 C than -5 C. I believe the original purpose of toBest was to find a value when converted that is closest to 1. That works well for something like 1000 m as one could argue that 1 km is the best value, since it is a simplified representation of the original unit value. So, I don't believe there is a way to get toBest to work for all measures, especially if the measure uses a shift or transformation to achieve the conversion.

I'm going to give this more thought but I just wanted to give you an update and see if you have any further thoughts.

Taar avatar Apr 17 '22 22:04 Taar

I was also thinking about the issue at hand, indeed it is subjective what the best representation is in any given units system. Actually what the best units are might very well depend on the application (ie. liters for fluids vs m3 for solids), and I see that with your library it is perfectly possible to define such application specific units systems. But I think it might be worthwhile to define more systems than "SI" and "Imperial" out of the box ie. something like "Scientific-SI" and "Technical-SI" or sorts. Where scientific would prefer [kelvin, pascal, m3, m/s] and technical would prefer [celsius, bar, liters, km/h], which are actually not si ;).

What is unexpected is switching between a absolute and a relative measurement system [C, K], i don't think there is a merit in that. A physicist probably doesnt want to see measurements in celsius and a meteorologist doesnt want to use kelvin in winter. But as said, thats just an opinion.

mzihlmann avatar Apr 23 '22 17:04 mzihlmann

That said, the issue raised here is actually far simpler. The output of toBest will probably always produce unexpected results for some people in some applications - but that is fine as long as you can include/exclude units as you go. the issue here is that if you exclude the target unit, then the output is null.

mzihlmann avatar Apr 23 '22 19:04 mzihlmann

@Taar

And in the case of temperatures, there isn't really a better representation of -5 C than -5 C.

Shouldn't it be reasonably expected to produce -5 C, rather than null, then?

facetious avatar Mar 28 '24 21:03 facetious