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

Should we add zero_Celsius point origin? #506

Closed
mpusz opened this issue Oct 19, 2023 · 5 comments
Closed

Should we add zero_Celsius point origin? #506

mpusz opened this issue Oct 19, 2023 · 5 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@mpusz
Copy link
Owner

mpusz commented Oct 19, 2023

Yesterday, I stumbled upon this article: https://randomascii.wordpress.com/2023/10/17/localization-failure-temperature-is-hard/

and prototyped the following solution for it: https://godbolt.org/z/6jo6xqeb8.

Even though the "ice point" is the correct name for the beginning of the Celsius scale, it looks a bit inconsistent and harder to use compared to Fahrenheits:

const quantity_point max = si::ice_point + 43. * deg_C;
std::cout << "max: " << max.quantity_from(si::ice_point) << " (" << max.quantity_from(usc::zero_Fahrenheit).in(deg_F) << ")\n";
const quantity_point max = usc::zero_Fahrenheit + 109. * deg_F;
std::cout << "max: " << max.quantity_from(usc::zero_Fahrenheit) << " (" << max.quantity_from(si::ice_point).in(deg_C) << ")\n";

Should we add zero_Celsius as an alias for si::ice_point as well to improve the usability? If so, should the zero_Celsius be its own strong type (derived from si::ice_point) or is it enough to just make it an object of si::ice_point type. The difference will be visible in types presented in compile-time errors.

@mpusz mpusz added enhancement New feature or request question Further information is requested labels Oct 19, 2023
@Spammed
Copy link

Spammed commented Oct 19, 2023

I would say: 'zero_Celsius' is a synonym (or alias) for 'si::ice_point' and not a (derived) kind of a 'si::ice_point'.
(I have to ask: Is Kelvin a Temperature-Distance? zero_Celsius - si::ice_point == 0 K ?)

@mpusz
Copy link
Owner Author

mpusz commented Oct 19, 2023

I didn't mean it to be treated as a derived thing. Inheritance here is just an implementation detail to create a strongly typed name. We do it for other entities as well. For example:

inline constexpr struct second : decltype(si::second) {} second;

so what I meant was something like this:

inline constexpr struct zero_Celsius : decltype(ice_point) {} zero_Celsius;

but we can also do:

inline constexpr ice_point zero_Celsius;

which will not introduce a new type, and the user will still see isq::ice_point even when zero_Celsius is used in the code.

@mpusz
Copy link
Owner Author

mpusz commented Oct 19, 2023

Is Kelvin a Temperature-Distance?

Kelvin is a unit. quantity<si::kelvin> is a differential/distance/vector type. quantity_point<si::kelvin, absolute_zero> is a point type with the internal quantity value being stored relative to the absolute_zero point.

zero_Celsius - si::ice_point == 0 K

Yes, that is true. Subtracting two points gives a quantity. As those are the same points, the distance between them is zero. The only exception when we can't subtract two points is when they are absolute_point_origins as those are unaware of the unit.

@chiphogg
Copy link
Collaborator

For posterity, here's my take on this issue (as shared in our recent WG21 meeting):

  • Yes, we should definitely provide a zero_Celsius type to represent the origin. We don't want to force users to rely on implicit knowledge, such as the fact that the "zero" of Celsius is the ice point: better to express intent clearly.
  • It should probably also be a strong type, not an alias for the ice point, because that will make the compiler errors easier to interpret.

@mpusz
Copy link
Owner Author

mpusz commented May 30, 2024

Done some time ago

@mpusz mpusz closed this as completed May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants