Elements
6.3.1
A C++ base framework for the Euclid Software.
Loading...
Searching...
No Matches
ElementsKernel
ElementsKernel
_impl
Number.tpp
Go to the documentation of this file.
1
21
// IWYU pragma: private, include "ElementsKernel/Number.h"
22
23
#ifndef ELEMENTSKERNEL_ELEMENTSKERNEL_NUMBER_IMPL_
24
#error "This file should not be included directly! Use ElementsKernel/Number.h instead"
25
#else
26
27
#include <cmath>
// for round
28
#include <type_traits>
// for is_floating_point, is_integral
29
30
namespace
Elements
{
31
32
template
<
typename
TargetType,
typename
SourceType>
33
TargetType
numberCast
(
const
SourceType& s) {
34
35
using
std::is_floating_point
;
36
using
std::is_integral
;
37
using
std::round
;
38
39
TargetType t =
static_cast<
TargetType
>
(
s
);
40
41
if
(is_floating_point<SourceType>::value && is_integral<TargetType>::value) {
42
t =
static_cast<
TargetType
>
(
round
(s));
43
}
44
45
return
t;
46
}
47
48
}
// namespace Elements
49
50
#endif
// ELEMENTSKERNEL_ELEMENTSKERNEL_NUMBER_IMPL_
Elements::numberCast
ELEMENTS_API TargetType numberCast(const SourceType &s)
this function is a number cast. It behaves exactly as a static_cast except when casting from a floati...
std::is_floating_point
std::is_integral
Elements::Kernel::Units::s
constexpr double s
Definition
SystemOfUnits.h:121
Elements
Definition
Auxiliary.h:43
std::round
T round(T... args)
Generated by
1.11.0