OptrisOptrisDocumentation

Documentation/OTC SDK/OTC SDK — C++ API referencev12.0

optris::sdk::Temperatures

Converting, rounding and labelling a temperature for a person.

Every function here is pure: it touches no camera, no file and no process state, and is safe from any thread.

Converting never rounds: Converting never rounds FromCelsius(), ToCelsius() and the two difference functions are plain arithmetic in double precision. So a value typed in one unit survives the trip into Celsius and back: 70.1 F is stored as 21.1666... C and shown again as 70.1 F. Rounding the Celsius value to a tenth first would store 21.2 C, which reads back as 70.2 F.

Rounding happens once, when the number becomes text: Rounding happens once, when the number becomes text Format() and FormatDifference() convert first and then round once, in the unit shown, half away from zero: 21.25 becomes "21.3" and -21.25 becomes "-21.3" at one decimal.

"Half" is judged on the decimal number the double stands for, which is the shortest decimal that reads back as the same double, and so the number a program prints for it. A double cannot hold 2.675 exactly (the nearest one is 2.67499999999999982236...), but the shortest decimal for that double is 2.675, so it rounds to "2.68" at two decimals, as a person rounding 2.675 on paper would. The double just below it is a different number, 2.6749999999999994, and rounds to "2.67". There is no tolerance beyond that: nothing is nudged towards a half.

A result that rounds to zero is written without a sign: -0.04 at one decimal is "0.0", because "-0.0" reads as a cold reading.

The text has no digit grouping, an ASCII - for a negative value and decimal_separator before the decimals, and depends on nothing else: the process locale never reaches it.

What is refused: What is refused A TemperatureUnit other than the two above, decimals outside 0 to 15, and a decimal separator other than . or , are refused with InvalidArgumentException. NaN and infinity are not refused: the conversions carry them through, and Format() writes them as an empty string, so the application decides how it shows a missing value.

Public static functions

FromCelsius

static auto FromCelsius(double celsius, TemperatureUnit unit) -> double

A temperature (a point on the scale) from degrees Celsius into unit. Does not round.

ToCelsius

static auto ToCelsius(double value, TemperatureUnit unit) -> double

A temperature in unit back into degrees Celsius, for storing what a person typed. Does not round.

FromKelvinDifference

static auto FromKelvinDifference(double kelvin, TemperatureUnit unit) -> double

A temperature difference (a distance on the scale) from kelvin into degrees of unit: K x 9/5 for Fahrenheit, with no offset. Does not round.

ToKelvinDifference

static auto ToKelvinDifference(double value, TemperatureUnit unit) -> double

A temperature difference in degrees of unit back into kelvin. Does not round.

Symbol

static auto Symbol(TemperatureUnit unit) -> const char *

The unit's symbol in UTF-8: the degree sign (U+00B0) followed by C or F. Static storage; never null.

Format

static auto Format(double celsius, TemperatureUnit unit, int decimals, char decimal_separator='.') -> std::string

A Celsius temperature as text in unit: converted, then rounded once, half away from zero, to decimals decimals. Without the symbol. NaN and infinity give an empty string.

Parameters

Name Description
celsius The temperature, in degrees Celsius.
unit The unit to show it in.
decimals How many decimals, 0 to 15.
decimal_separator . (the default) or ,.

Exceptions

Name Description
InvalidArgumentException as described on the class.

FormatDifference

static auto FormatDifference(double kelvin, TemperatureUnit unit, int decimals, char decimal_separator='.') -> std::string

A temperature difference in kelvin as text in degrees of unit: converted with no offset, then rounded exactly as Format() rounds. 2 K in Fahrenheit is "3.6".

Exceptions

Name Description
InvalidArgumentException as described on the class.

Public functions

Temperatures

Temperatures()=delete