C++ Logo

std-proposals

Advanced search

Re: [std-proposals] On the standardization of mp-units P3045R1

From: Charles R Hogg <charles.r.hogg_at_[hidden]>
Date: Tue, 18 Jun 2024 16:27:36 -0400
On Tue, Jun 18, 2024 at 3:58 PM Tiago Freire <tmiguelf_at_[hidden]> wrote:

> > I'll reiterate my call for you to explain how you think a hypothetical
> standard units library ought to tell its users how to convert temperature
> differences from Celsius to Fahrenheit. Seriously: what line of code do
> you want to tell them to write?
>
>
>
> You don’t have temperature in Celsius or Fahrenheit.
>

Thanks for answering! So it seems like your answer is "the standard units
library *should not support* converting temperature differences from
Celsius to Fahrenheit, because these temperature differences should not be
representable in the first place". It's certainly not the approach I'd
prefer, but I guess it's one point of view.

But that's not the end of the story --- let's go further and imagine that
this design gets accepted. Imagine a climate scientist *has* a temperature
increase of 1.5 degrees Celsius, and *wants* to express it in Fahrenheit.
What will happen? Will the library prevent this?

It seems to me that the likeliest outcome is that they'll create a
*temperature* of 1.5 degrees Celsius, and request conversion to a
*temperature* in Fahrenheit, at which point the library happily provides a
result of 34.7 degrees F, rather than the 2.7 degrees F I imagine they
would have wanted.

Your original post provided a great service --- a concrete example where
the current units library proposal would return a grossly incorrect result
for code that looks correct. We can fix this if we avoid making it easy to
create a quantity in situations where a quantity point is needed. By
contrast, it seems to me that your proposal suffers from the exact same
defect --- good-looking code that produces grossly incorrect results ---
except that in this case, I'm at a loss for how we could fix it.

Cheers,
Chip

Received on 2024-06-18 20:27:48