20#ifndef INCLUDE_REAL_TYPE_HPP
21#define INCLUDE_REAL_TYPE_HPP
47 :
d_(static_cast<double>(d))
76 inline operator T()
const {
return static_cast<T
>(
d_); }
77 inline operator bool()
const {
return (
d_ != 0.0); }
95 #define real_define_inequalities(Type) \
96 inline type operator+ (const Type r0, const type r1) { return type(r0 + r1.d_); } \
97 inline type operator- (const Type r0, const type r1) { return type(r0 - r1.d_); } \
98 inline type operator* (const Type r0, const type r1) { return type(r0 * r1.d_); } \
99 inline type operator/ (const Type r0, const type r1) { return type(r0 / r1.d_); } \
100 inline bool operator< (const Type r0, const type r1) { return (r0 < r1.d_); } \
101 inline bool operator> (const Type r0, const type r1) { return (r0 > r1.d_); } \
102 inline bool operator<=(const Type r0, const type r1) { return (r0 <= r1.d_); } \
103 inline bool operator>=(const Type r0, const type r1) { return (r0 >= r1.d_); } \
104 inline bool operator==(const Type r0, const type r1) { return (r0 == r1.d_); } \
105 inline bool operator!=(const Type r0, const type r1) { return (r0 != r1.d_); } \
106 inline type operator+ (const type r0, const Type r1) { return type(r0.d_ + r1); } \
107 inline type operator- (const type r0, const Type r1) { return type(r0.d_ - r1); } \
108 inline type operator* (const type r0, const Type r1) { return type(r0.d_ * r1); } \
109 inline type operator/ (const type r0, const Type r1) { return type(r0.d_ / r1); } \
110 inline bool operator< (const type r0, const Type r1) { return (r0.d_ < r1); } \
111 inline bool operator> (const type r0, const Type r1) { return (r0.d_ > r1); } \
112 inline bool operator<=(const type r0, const Type r1) { return (r0.d_ <= r1); } \
113 inline bool operator>=(const type r0, const Type r1) { return (r0.d_ >= r1); } \
114 inline bool operator==(const type r0, const Type r1) { return (r0.d_ == r1); } \
115 inline bool operator!=(const type r0, const Type r1) { return (r0.d_ != r1); } \
129 class numeric_limits<
real::type>
135 static const bool is_specialized =
true;
136 static number_type (min) () {
return std::numeric_limits<double>::min(); }
137 static number_type (max) () {
return std::numeric_limits<double>::max(); }
145 static const int digits = std::numeric_limits<double>::digits;
146 static const int digits10 = std::numeric_limits<double>::digits10;
147 static const int radix = std::numeric_limits<double>::radix;
148 static const int min_exponent = std::numeric_limits<double>::min_exponent;
149 static const int min_exponent10 = std::numeric_limits<double>::min_exponent10;
150 static const int max_exponent = std::numeric_limits<double>::max_exponent;
151 static const int max_exponent10 = std::numeric_limits<double>::max_exponent10;
152 static const bool has_infinity = std::numeric_limits<double>::has_infinity;
153 static const bool has_quiet_NaN = std::numeric_limits<double>::has_quiet_NaN;
154 static const bool has_signaling_NaN = std::numeric_limits<double>::has_signaling_NaN;
155 static const bool has_denorm_loss = std::numeric_limits<double>::has_denorm_loss;
156 static const bool is_signed = std::numeric_limits<double>::is_signed;
157 static const bool is_integer = std::numeric_limits<double>::is_integer;
158 static const bool is_exact = std::numeric_limits<double>::is_exact;
159 static const bool is_iec559 = std::numeric_limits<double>::is_iec559;
160 static const bool is_bounded = std::numeric_limits<double>::is_bounded;
161 static const bool is_modulo = std::numeric_limits<double>::is_modulo;
162 static const bool traps = std::numeric_limits<double>::traps;
163 static const float_denorm_style has_denorm = std::numeric_limits<double>::has_denorm;
164 static const float_round_style round_style = std::numeric_limits<double>::round_style;
174 static const double e = 2.71828182845904523536028747135266249775724709369996;
175 static const double pi = 3.14159265358979323846264338327950288419716939937510;
176 static const double pi_2 = 1.57079632679489661923132169163975144209858469968755;
177 static const double pi_4 = 0.78539816339744830961566084581987572104929234984378;
178 static const double pi_180 = 0.01745329251994329576923690768488612713442871888542;
179 static const double _1_pi = 0.31830988618379067153776752674502872406891929148091;
180 static const double _2_pi = 0.63661977236758134307553505349005744813783858296183;
181 static const double _180_pi = 57.29577951308232087679815481410517033240547246656443;
182 static const double log2 = 0.69314718055994530941723212145817656807550013436026;
183 static const double sqrt2 = 1.41421356237309504880168872420969807856967187537695;
228 inline bool is_true (
const type v) {
return (v !=
type(0)); }
235 static const type epsilon =
type(0.0000000001);
243 return type(v + (0.5 * v * v));
250 static const type epsilon =
type(0.0000000001);
263 return (
type(-0.5) * v +
type(1)) * v;
266 return type(std::numeric_limits<double>::quiet_NaN());
285 return sqrt((v0 * v0) + (v1 * v1));
301 else if (v <
type(0))
return type(-1);
302 else return type( 0);
317 const bool v0_true = is_true(v0);
318 const bool v1_true = is_true(v1);
319 if ((v0_true && v1_true) || (!v0_true && !v1_true))
327 #if defined(_MSC_VER) && (_MSC_VER < 1900)
330 static const type c[] = {
331 type( 1.26551223),
type(1.00002368),
332 type( 0.37409196),
type(0.09678418),
333 type(-0.18628806),
type(0.27886807),
334 type(-1.13520398),
type(1.48851587),
339 c[0] + t * (c[1] + t *
340 (c[2] + t * (c[3] + t *
341 (c[4] + t * (c[5] + t *
342 (c[6] + t * (c[7] + t *
343 (c[8] + t * (c[9]))))))))));
345 return (v >=
type(0)) ? result : -result;
347 return ::erf(
static_cast<double>(v));
static number_type denorm_min()
static number_type infinity()
static number_type round_error()
static number_type quiet_NaN()
static number_type epsilon()
static number_type signaling_NaN()
static number_type lowest()
static const double _1_pi
static const double _2_pi
static const double _180_pi
static const double sqrt2
static const double pi_180
type pow(const type v0, const type v1)
type root(const type v0, const type v1)
type nor(const type v0, const type &v1)
bool operator>=(const type r0, const type r1)
bool operator<(const type r0, const type r1)
type modulus(const type v0, const type v1)
type nequal(const type v0, const type v1)
bool is_false(const type v)
bool operator<=(const type r0, const type r1)
type atan2(const type v0, const type v1)
type operator*(const type r0, const type r1)
type shr(const type v0, const type v1)
type max(const type v0, const type v1)
type operator/(const type r0, const type r1)
type logn(const type v0, const type v1)
type xnor(const type v0, const type &v1)
type nand(const type v0, const type &v1)
type roundn(const type v0, const type v1)
type equal(const type v0x, const type v1x)
type operator+(const type r0, const type r1)
type operator-(const type r0, const type r1)
type expm1(const type vx)
type shl(const type v0, const type v1)
type hypot(const type v0, const type v1)
bool operator>(const type r0, const type r1)
type min(const type v0, const type v1)
#define real_define_inequalities(Type)
type & operator*=(const type &r)
type & operator+=(const type &r)
type & operator/=(const type &r)
bool operator==(const type &r) const
bool operator!=(const type &r) const
type & operator-=(const type &r)
type & operator=(const T d)
type & operator=(const double &d)