C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Tue, 18 Jun 2024 18:21:49 -0700
On Tuesday 18 June 2024 12:57:58 GMT-7 Tiago Freire via Std-Proposals 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.

Unfortunately, you do.

I remember when I proposed in a specification we should serialise temperatures
in millikelvins because that would allow us to be precise and only use
(positive) integers. That was shot down because there are certain scenarios
where the conversion between °F and °C/K is disallowed due to regulations and
certifications: medical devices, for example. If you have a temperature probe
that records in Fahrenheit, it needs to transmit in that and be recorded in
that.

I personally think that's a pointless requirement. The probes will not have
the precision or accuracy that the requirement presupposes they have and
moreover some of that will be lost in the first place by using floating point.

But I didn't make the rules.

I can see the value in avoiding back-and-forth conversions.
1) user inputs 98.1 °F
2) value is read from UI as 98.09999999999999432
3) value is stored to 309.87222222222220580 K
4) value is converted back as 98.10000000000000853 °F

The error here is small (1.45e-16, even though it is 2048 epsilons), but you
can imagine how it can become bigger with each successive conversion,
especially if it goes through underpowered devices operating in single-
precision FP.
-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Fleet Systems Engineering

Received on 2024-06-19 01:21:51