-
Notifications
You must be signed in to change notification settings - Fork 387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Temperature standard arithmetic (WIP) #575
Conversation
These are instead handled by standard arithmetic, now generated for Temperature.
Use ToString() and Enum.Parse() to get slightly more robust conversion without having to generate a switch statement for all cases.
This text was removed from 3.x to 4.x migration wiki page and should be added back to a future migration page if we do complete this PR: Change Temperature arithmetic back to use base unit KelvinInstead of a special case for Temperature, we now have the exact same arithmetic as for other quantities. Temperature celsius30, celsius20; // Assume assigned..
// Before
var x = celsius30 + celsius20; // Not possible
TemperatureDelta deltaCelsius10 = celsius30 - celsius20; // delta 10 degrees Celsius
// After - this can get confusing if you are working with Celsius or Fahrenheit
Temperature celsius323 = celsius30 + celsius20;
Temperature minus263Celsius = celsius30 - celsius20;
// For addition/subtraction when working with Celsius or Fahrenheit, you probably want to use TemperatureDelta
TemperatureDelta deltaCelsius20 = TemperatureDelta.FromDegreesCelsius(20);
Temperature celsius50 = celsius30 + deltaCelsius20;
Temperature celsius10 = celsius30 - deltaCelsius20;
// Or use these convenience methods
Temperature deltaCelsius10 = celsius30.ToDelta(celsius20);
TemperatureDelta deltaCelsius10 = TemperatureDelta.FromTemperatures(celsius30, celsius20); |
Closing this. We can keep the branch alive for some time and can always reopen the PR later. |
Do not merge.
This change is still up for debate. See discussions in #518, #550 and #560.
Created this PR just to have all the work of #550 and #560 in one place in case we want to standardize temperature arithmetic later. We decided to postpone this for v4 as we couldn't agree on whether this change was for the better or not.
TemperatureDelta
)Multiply()
andDivide()
methods-
operator overloadTemperature.ToDelta(other)
instance methodTemperatureDelta.FromTemperatures(left, right)
static methodax + b
linear relationship instead of just a factor conversionax
).Fixes #518