ChimeraTK-DeviceAccess 03.26.00
Loading...
Searching...
No Matches
ChimeraTK::numeric Namespace Reference

Namespaces

namespace  detail
 Replacement for std::round() which also works constexpr and also casts to the target type in the same step.
 

Concepts

concept  Integral
 Concept to require an integral data type incl.
 
concept  Arithmetic
 Concept to require a numeric data type in templates.
 
concept  ArithmeticOrVoid
 Concept to require a numeric data type in templates, or ChimeraTK::Void.
 

Functions

template<ArithmeticOrVoid TO, ArithmeticOrVoid FROM>
constexpr TO convert (FROM value)
 Convert numeric data types with proper rounding and clamping to the target value range.
 

Function Documentation

◆ convert()

template<ArithmeticOrVoid TO, ArithmeticOrVoid FROM>
constexpr TO ChimeraTK::numeric::convert ( FROM  value)
constexpr

Convert numeric data types with proper rounding and clamping to the target value range.

The exact behaviour is defined as follows:

  • integer target types: both positive and negative overflows clamp to the closest value of the target type.
  • unsigned integer targets: negative input values give always 0
  • double-to-single floats: overflows clamp, Inf and NaN is kept as is
  • float-to-integer: rounding to nearest integer
  • bool targets: any non-zero value (after rounding to nearest integer) is true (also negative values)

Definition at line 123 of file NumericConverter.h.