Skip to content
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

Closed
wants to merge 10 commits into from

Conversation

angularsen
Copy link
Owner

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.

  • Generate default arithmetic (no special case returning TemperatureDelta)
  • Remove Multiply() and Divide() methods
  • Remove custom - operator overload
  • Add Temperature.ToDelta(other) instance method
  • Add TemperatureDelta.FromTemperatures(left, right) static method
  • Create tests for addition and subtraction of Temperature
  • Fix arithmetic code generation for all quantities, it produced wrong results for Temperature and would also be wrong if any other quantities had units that have different zero values (ax + b linear relationship instead of just a factor conversion ax).

Fixes #518

@angularsen
Copy link
Owner Author

angularsen commented Dec 16, 2018

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 Kelvin

Instead of a special case for Temperature, we now have the exact same arithmetic as for other quantities.
Previously subtracting two temperatures would return a TemperatureDelta. Instead, you can now add and subtract two temperatures and they will return a new Temperature with addition/subtraction performed in base unit Kelvin while maintaining the left hand argument's unit.

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);

@angularsen
Copy link
Owner Author

Closing this. We can keep the branch alive for some time and can always reopen the PR later.

@angularsen angularsen closed this Feb 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant