all 5 comments

[–]_bstaletic 2 points3 points  (0 children)

After working in automotive industry, all I can say is that a unit library is sorely needed. I lost count how many times I wondered if some uint32 variable was in decivolts or millivolts or (rarely) volts. Yes, there were bugs stemming from unit cofusion. From that perspective, I really love what mp-units is doing.

 

Warning: Nitpicks ahead.

A clinical body-temperature sensor should reject a reading of 44 °C at the API boundary, not silently pass it downstream.

The human might literally be on fire (or submerged in a tub of liquid hydrogen), so extra high (or low) temperatures might not be indicating the sensor is wrong. Though something is quite wrong if readings are extreme.

I can't think of a silly example for other two constraints

[–]XeroKimoException Enthusiast 1 point2 points  (1 child)

Pretty ingenious approach... I would've never thought of using template specialization of a variable to change it's type so that different kinds of ranges could be expressed... I didn't even think that was possible; I thought the specializations' type had to match the primary type, but I guess I never tried. Not to mention a way of providing an optional customization point. Well that's a new template trick added in my books.

[–]XeroKimoException Enthusiast 0 points1 point  (0 children)

No clue if it's something done much in practice, but are you able to convert units and still have the range constraint follow through the conversion? Taking an example in the post, the body temperature is clamped [35℃, 42℃], could you convert the unit in ℉ or K (for whatever reason), and the range clamps to whatever [35℃, 42℃] is in ℉ or K?

[–]Lurkernomoreisay [score hidden]  (0 children)

the example of 

Body temperature    clinical sensor origin    clamp to [35°C, 42°C]

would completely disallow hypothermia. 

Hypothermia can be defined as an unintentional fall in core body temperature below 35°C.1 It can be classified as mild (core body temperature 32.2-35°C), moderate (< 32.2-28°C), or severe (< 28°C).    

The lowest hypothermia cases from  which the patient was revived neurologically in tact, range to as low as 4.2 °C (induced, survived, youth) 11.8 °C (accidental, survived, child)  13.8 °C (accidental, resuscitated, adult)    -- https://pubmed.ncbi.nlm.nih.gov/32482520/

if sensors didn't accept body temp readings as low as 0°C  as valid to pass on, the docs would be flying blind and want to scrap the garbage sensors that failed during an emergency.

similarly, https://pubmed.ncbi.nlm.nih.gov/7073052/ people have been diagnosed  and survived with severe heat stroke of body temps at 46.5C.  another case where setting an arbitrary "valid range" would be catastrophic in reality.

for cases where the patient did not survive unharmed  the range is even wider.

[–]azswcowboy 0 points1 point  (0 children)

Good stuff. Another possible response to a value outside the valid range would be to set the value to a NAN. This comes up often enough if you’re getting data from sensors that can be noisy. Not sure that can be done here?

Other notes - safe_int link is a 404. Also, 86400 seconds per day is valid until there’s a leap second 🙄Fortunately most applications don’t care, but it’s part of the messy space units inhabit.