9 namespace numeral_priv {
template<
class T>
struct Info; }
23 typedef numeral_priv::Info<T> Info;
28 typedef typename Info::Int
Int;
38 constexpr T
min()
const {
return _info.min; }
40 constexpr T
max()
const {
return _info.max; }
47 typedef numeral_priv::Info<T> Info;
52 typedef typename Info::Int
Int;
62 constexpr T
min()
const {
return _info.min(); }
64 constexpr T
max()
const {
return _info.max(); }
66 constexpr T
smallest()
const {
return _info.smallest(); }
68 constexpr T
epsilon()
const {
return _info.epsilon(); }
70 constexpr T
inf()
const {
return _info.inf(); }
72 constexpr T
nan()
const {
return _info.nan(); }
88 template<class To, class From, typename std::enable_if<std::is_signed<From>::value && std::is_unsigned<To>::value &&
sizeof(To) >=
sizeof(From),
int>::type=0>
89 To numeric_cast(From s) {
assert(s >= 0);
return static_cast<To
>(s); }
91 template<class To, class From, typename std::enable_if<std::is_unsigned<From>::value && std::is_signed<To>::value &&
sizeof(To) >=
sizeof(From),
int>::type=0>
92 To numeric_cast(From u) {
assert(static_cast<To>(u) >= 0);
return static_cast<To
>(u); }
94 template<class To, class From, typename std::enable_if<std::is_signed<From>::value == std::is_signed<To>::value &&
sizeof(To) >=
sizeof(From),
int>::type=0>
95 To numeric_cast(From i) {
return static_cast<To
>(i); }
97 template<class To, class From, typename std::enable_if<std::is_signed<From>::value &&
sizeof(To) <
sizeof(From),
int>::type=0>
98 To numeric_cast(From s) {
assert(s >= static_cast<From>(numeral<To>().min()) && s <= static_cast<From>(numeral<To>().max()));
return static_cast<To
>(s); }
100 template<class To, class From, typename std::enable_if<std::is_unsigned<From>::value &&
sizeof(To) <
sizeof(From),
int>::type=0>
101 To numeric_cast(From u) {
assert(u <= static_cast<From>(numeral<To>().max()));
return static_cast<To
>(u); }
105 namespace numeral_priv
107 template<>
struct Info<
int8>
111 typedef Float_
Real_;
112 static const int8 min = -0x7F - 1;
113 static const int8 max = 0x7F;
116 template<>
struct Info<
uint8>
120 typedef Float_
Real_;
121 static const uint8 min = 0;
122 static const uint8 max = 0xFFU;
125 template<>
struct Info<
int16>
129 typedef Float_
Real_;
130 static const int16 min = -0x7FFF - 1;
131 static const int16 max = 0x7FFF;
134 template<>
struct Info<
uint16>
138 typedef Float_
Real_;
139 static const uint16 min = 0;
140 static const uint16 max = 0xFFFFU;
143 template<>
struct Info<
int32>
147 typedef Float_
Real_;
148 static const int32 min = -0x7FFFFFFF - 1;
149 static const int32 max = 0x7FFFFFFF;
152 template<>
struct Info<
uint32>
156 typedef Float_
Real_;
157 static const uint32 min = 0;
158 static const uint32 max = 0xFFFFFFFFU;
161 template<>
struct Info<
int64>
165 typedef Double_
Real_;
166 static const int64 min = -0x7FFFFFFFFFFFFFFFL - 1;
167 static const int64 max = 0x7FFFFFFFFFFFFFFFL;
170 template<>
struct Info<
uint64>
174 typedef Double_
Real_;
175 static const uint64 min = 0;
176 static const uint64 max = 0xFFFFFFFFFFFFFFFFUL;
179 template<>
struct Info<float>
183 typedef Float_
Real_;
185 constexpr
float min()
const {
return -3.402823466e+38f; }
186 constexpr
float max()
const {
return 3.402823466e+38f; }
187 constexpr
float smallest()
const {
return 1.175494351e-38f; }
188 constexpr
float epsilon()
const {
return 1.192092896e-07f; }
189 constexpr
float one()
const {
return 1.f; }
190 constexpr
float inf()
const {
return 1.f / (1.f - one()); }
191 constexpr
float nan()
const {
return 0.f / (1.f - one()); }
194 template<>
struct Info<double>
198 typedef Double_
Real_;
200 constexpr
double min()
const {
return -1.7976931348623158e+308; }
201 constexpr
double max()
const {
return 1.7976931348623158e+308; }
202 constexpr
double smallest()
const {
return 2.2250738585072014e-308; }
203 constexpr
double epsilon()
const {
return 2.2204460492503131e-016; }
204 constexpr
double one()
const {
return 1.0; }
205 constexpr
double inf()
const {
return 1.0 / (1.0 - one()); }
206 constexpr
double nan()
const {
return 0.0 / (1.0 - one()); }
210 template<>
class Numeral<
int8> :
public NumeralInt<int8> {};
211 template<>
class Numeral<
uint8> :
public NumeralInt<uint8> {};
212 template<>
class Numeral<
int16> :
public NumeralInt<int16> {};
213 template<>
class Numeral<
uint16> :
public NumeralInt<uint16> {};
214 template<>
class Numeral<
int32> :
public NumeralInt<int32> {};
215 template<>
class Numeral<
uint32> :
public NumeralInt<uint32> {};
216 template<>
class Numeral<
int64> :
public NumeralInt<int64> {};
217 template<>
class Numeral<
uint64> :
public NumeralInt<uint64> {};
218 template<>
class Numeral<float> :
public NumeralFloat<float> {};
219 template<>
class Numeral<double> :
public NumeralFloat<double> {};
224 #include "Honey/Math/platform/Numeral.h"
constexpr T smallest() const
Smallest representable value (close to zero)
Definition: Numeral.h:66
constexpr T min() const
Minimum possible value for type.
Definition: Numeral.h:62
unsigned int uint32
Definition: Core.h:16
static const int sizeBits
Size of type in bits.
Definition: Numeral.h:59
Info::Real Real
Real representation of type.
Definition: Numeral.h:54
Numeric type info for integer types.
Definition: Numeral.h:21
constexpr T epsilon() const
Smallest value such that 1.0 + epsilon != 1.0.
Definition: Numeral.h:68
constexpr T max() const
Maximum possible value for type.
Definition: Numeral.h:40
Info::Int Int
Integer representation of type.
Definition: Numeral.h:28
char int8
Definition: Core.h:11
unsigned long long uint64
Definition: Core.h:22
constexpr T min() const
Minimum possible value for type (negative for signed types)
Definition: Numeral.h:38
constexpr T max() const
Maximum possible value for type.
Definition: Numeral.h:64
unsigned char uint8
Definition: Core.h:12
int int32
Definition: Core.h:15
#define assert(...)
Forwards to assert_#args. See assert_1(), assert_2().
Definition: Debug.h:24
Info::Real_ Real_
Real operations and constants class.
Definition: Numeral.h:32
constexpr Numeral< T > numeral()
Get numeric type info safely from a static context.
Definition: Numeral.h:78
unsigned short uint16
Definition: Core.h:14
float Real
Real number type. See Real_ for real number operations and constants.
Definition: Real.h:21
Numeric type information, use numeral() to get instance safely from a static context.
Definition: Numeral.h:17
static const int sizeBits
Size of type in bits.
Definition: Numeral.h:35
Numeral< Real >::Real_ Real_
Operations and constants for Real type. See Float_, Double_.
Definition: Real.h:25
constexpr T inf() const
Infinity. ie. 1.0 / 0.0.
Definition: Numeral.h:70
long long int64
Definition: Core.h:21
Numeric type info for floating point types.
Definition: Numeral.h:45
Info::Real_ Real_
Real operations and constants class.
Definition: Numeral.h:56
Info::Real Real
Real representation of type.
Definition: Numeral.h:30
constexpr T nan() const
Not a number. ie. 0.0 / 0.0, sqrt(-1)
Definition: Numeral.h:72
short int16
Definition: Core.h:13
Global Honeycomb namespace.
Info::Int Int
Integer representation of type.
Definition: Numeral.h:52