29 #ifndef VC_COMMON_CONST_H_
30 #define VC_COMMON_CONST_H_
32 #include <type_traits>
33 #include <Vc/global.h>
35 namespace Vc_VERSIONED_NAMESPACE
40 template <
int exponent> constexpr
double exponentToFloat(std::integral_constant<bool, true>);
41 template <
int exponent> constexpr
double exponentToFloat(std::integral_constant<bool, false>);
42 template <> constexpr
double exponentToFloat<0>(std::integral_constant<bool, true>)
46 template <> constexpr
double exponentToFloat<0>(std::integral_constant<bool, false>)
50 template <> constexpr
double exponentToFloat<-32>(std::integral_constant<bool, true>)
52 return 1. / (65536. * 65536.);
54 template <> constexpr
double exponentToFloat<32>(std::integral_constant<bool, false>)
56 return 65536. * 65536.;
58 template <> constexpr
double exponentToFloat<-64>(std::integral_constant<bool, true>)
60 return 1. / (65536. * 65536. * 65536. * 65536.);
62 template <> constexpr
double exponentToFloat<64>(std::integral_constant<bool, false>)
64 return 65536. * 65536. * 65536. * 65536.;
66 template <
int exponent>
67 constexpr
double exponentToFloat(std::integral_constant<bool, false> negative)
69 return exponentToFloat<exponent - 1>(negative) * 2.0;
71 template <
int exponent>
72 constexpr
double exponentToFloat(std::integral_constant<bool, true> negative)
74 return exponentToFloat<exponent + 1>(negative) * 0.5;
76 template <
int sign,
unsigned long long mantissa,
int exponent> constexpr
double doubleConstant()
78 return (static_cast<double>((mantissa & 0x000fffffffffffffull) | 0x0010000000000000ull) /
79 0x0010000000000000ull) *
80 exponentToFloat<exponent>(std::integral_constant<bool, (exponent < 0)>()) * sign;
82 template <
int sign,
unsigned int mantissa,
int exponent> constexpr
float floatConstant()
84 return (static_cast<float>((mantissa & 0x007fffffu) | 0x00800000u) / 0x00800000u) *
86 exponentToFloat<exponent>(std::integral_constant<bool, (exponent < 0)>())) *
93 #endif // VC_COMMON_CONST_H_