44#ifndef LASS_GUARDIAN_OF_INCLUSION_NUM_FLOATING_POINT_CONSISTENCY_H
45#define LASS_GUARDIAN_OF_INCLUSION_NUM_FLOATING_POINT_CONSISTENCY_H
60 typedef Consistent<T> TSelf;
61 typedef typename util::CallTraits<T>::TValue TValue;
62 typedef typename util::CallTraits<T>::TParam TParam;
63 typedef typename util::CallTraits<T>::TReference TReference;
64 typedef typename util::CallTraits<T>::TConstReference TConstReference;
65 typedef num::NumTraits<T> TNumTraits;
76 Consistent(
const TSelf& other):
81 TSelf& operator=(
const TSelf& other)
92 TSelf operator-()
const
97 TSelf operator+()
const
102 TSelf& operator+=(
const TSelf& other)
107 TSelf& operator-=(
const TSelf& other)
112 TSelf& operator*=(
const TSelf& other)
117 TSelf& operator/=(
const TSelf& other)
123 void swap(TSelf& other)
125 std::swap(t_, other.t_);
134template <
typename T>
inline
135Consistent<T> operator+(
const Consistent<T>& a,
const Consistent<T>& b)
137 return Consistent<T>(a.value() + b.value());
140template <
typename T>
inline
141Consistent<T> operator-(
const Consistent<T>& a,
const Consistent<T>& b)
143 return Consistent<T>(a.value() - b.value());
146template <
typename T>
inline
147Consistent<T> operator*(
const Consistent<T>& a,
const Consistent<T>& b)
149 return Consistent<T>(a.value() * b.value());
152template <
typename T>
inline
153Consistent<T> operator/(
const Consistent<T>& a,
const Consistent<T>& b)
155 return Consistent<T>(a.value() / b.value());
158template <
typename T>
inline
159bool operator==(
const Consistent<T>& a,
const Consistent<T>& b)
161 return a.value() == b.value();
164template <
typename T>
inline
165bool operator!=(
const Consistent<T>& a,
const Consistent<T>& b)
170template <
typename T>
inline
171bool operator<(
const Consistent<T>& a,
const Consistent<T>& b)
173 return a.value() < b.value();
176template <
typename T>
inline
177bool operator>(
const Consistent<T>& a,
const Consistent<T>& b)
182template <
typename T>
inline
183bool operator<=(
const Consistent<T>& a,
const Consistent<T>& b)
188template <
typename T>
inline
189bool operator>=(
const Consistent<T>& a,
const Consistent<T>& b)
197template <
typename T>
inline
198Consistent<T> operator+(
const Consistent<T>& a,
const T& b)
200 return Consistent<T>(a.value() + b);
203template <
typename T>
inline
204Consistent<T> operator-(
const Consistent<T>& a,
const T& b)
206 return Consistent<T>(a.value() - b);
209template <
typename T>
inline
210Consistent<T> operator*(
const Consistent<T>& a,
const T& b)
212 return Consistent<T>(a.value() * b);
215template <
typename T>
inline
216Consistent<T> operator/(
const Consistent<T>& a,
const T& b)
218 return Consistent<T>(a.value() / b);
221template <
typename T>
inline
222bool operator==(
const Consistent<T>& a,
const T& b)
224 return a == Consistent<T>(b);
227template <
typename T>
inline
228bool operator!=(
const Consistent<T>& a,
const T& b)
233template <
typename T>
inline
234bool operator<(
const Consistent<T>& a,
const T& b)
236 return a < Consistent<T>(b);
239template <
typename T>
inline
240bool operator>(
const Consistent<T>& a,
const T& b)
245template <
typename T>
inline
246bool operator<=(
const Consistent<T>& a,
const T& b)
251template <
typename T>
inline
252bool operator>=(
const Consistent<T>& a,
const T& b)
260template <
typename T>
inline
261Consistent<T> operator+(
const T& a,
const Consistent<T>& b)
263 return Consistent<T>(a + b.value());
266template <
typename T>
inline
267Consistent<T> operator-(
const T& a,
const Consistent<T>& b)
269 return Consistent<T>(a - b.value());
272template <
typename T>
inline
273Consistent<T> operator*(
const T& a,
const Consistent<T>& b)
275 return Consistent<T>(a * b.value());
278template <
typename T>
inline
279Consistent<T> operator/(
const T& a,
const Consistent<T>& b)
281 return Consistent<T>(a / b.value());
284template <
typename T>
inline
285bool operator==(
const T& a,
const Consistent<T>& b)
287 return Consistent<T>(a) == b;
290template <
typename T>
inline
291bool operator!=(
const T& a,
const Consistent<T>& b)
296template <
typename T>
inline
297bool operator<(
const T& a,
const Consistent<T>& b)
299 return Consistent<T>(a) < b;
302template <
typename T>
inline
303bool operator>(
const T& a,
const Consistent<T>& b)
308template <
typename T>
inline
309bool operator<=(
const T& a,
const Consistent<T>& b)
314template <
typename T>
inline
315bool operator>=(
const T& a,
const Consistent<T>& b)
324template <
typename T>
inline
325Consistent<T>
abs(
const Consistent<T>& v)
330template <
typename T>
inline
331Consistent<T>
inv(
const Consistent<T>& v)
342template <
typename T>
inline
343Consistent<T> sqrt(Consistent<T> v)
345 return num::sqrt(v.value());
348template <
typename T>
inline
349Consistent<T>
pow(
const Consistent<T>& v,
const Consistent<T>& p)
351 return num::pow(v.value(), p.value());
354template <
typename T>
inline
355Consistent<T> exp(
const Consistent<T>& v)
357 return num::exp(v.value());
360template <
typename T>
inline
361Consistent<T> log(
const Consistent<T>& v)
363 return num::log(v.value());
366template <
typename T>
inline
367Consistent<T> cos(
const Consistent<T>& v)
369 return num::cos(v.value());
372template <
typename T>
inline
373Consistent<T> sin(
const Consistent<T>& v)
375 return num::sin(v.value());
378template <
typename T>
inline
379Consistent<T> tan(
const Consistent<T>& v)
381 return num::tan(v.value());
384template <
typename T>
inline
385Consistent<T> acos(
const Consistent<T>& v)
387 return num::acos(v.value());
390template <
typename T>
inline
391Consistent<T> asin(
const Consistent<T>& v)
393 return num::asin(v.value());
396template <
typename T>
inline
397Consistent<T> atan(
const Consistent<T>& v)
399 return num::atan(v.value());
402template <
typename T>
inline
403Consistent<T> atan2(
const Consistent<T>& y,
const Consistent<T>& x)
405 return num::atan2(y.value(), x.value());
408template <
typename T>
inline
409Consistent<T> floor(
const Consistent<T>& v)
411 return num::floor(v.value());
414template <
typename T>
inline
415Consistent<T> ceil(
const Consistent<T>& v)
417 return num::ceil(v.value());
420template <
typename T>
inline
421Consistent<T> round(
const Consistent<T>& v)
423 return num::round(v.value());
426template <
typename T>
inline
427Consistent<T> fractional(
const Consistent<T>& v)
429 return num::fractional(v.value());
432template <
typename T>
inline
433Consistent<T> div(
const Consistent<T>& v,
const Consistent<T>& m)
435 return num::div(v.value(), m.value());
438template <
typename T>
inline
439Consistent<T> mod(
const Consistent<T>& v,
const Consistent<T>& m)
441 return num::mod(v.value(), m.value());
445#define LASS_NUM_FLOATING_POINT_CONSISTENCY_DECLARE_NUMTRAITS(type)\
447 struct LASS_DLL NumTraits< Consistent< type > >\
450 typedef NumTraits< type > TBaseTraits;\
452 typedef Consistent< type > selfType;\
453 typedef type baseType;\
454 typedef type intervalType;\
457 isDistribution = TBaseTraits::isDistribution,\
458 isIntegral = TBaseTraits::isIntegral,\
459 isNative = TBaseTraits::isNative,\
460 isSigned = TBaseTraits::isSigned,\
461 hasInfinity = TBaseTraits::hasInfinity,\
462 hasNaN = TBaseTraits::hasNaN\
464 static const int memorySize;\
465 static const std::string name() { return "Consistent<" + TBaseTraits::name() + ">" ; }\
466 static const selfType one;\
467 static const selfType zero;\
468 static const selfType sNaN;\
469 static const selfType qNaN;\
470 static const selfType epsilon;\
471 static const selfType infinity;\
472 static const selfType min;\
473 static const selfType max;\
474 static const selfType minStrictPositive;\
475 static const selfType pi;\
476 static const selfType e;\
477 static const selfType sqrt2;\
478 static const selfType sqrtPi;\
481LASS_NUM_FLOATING_POINT_CONSISTENCY_DECLARE_NUMTRAITS(
float)
482LASS_NUM_FLOATING_POINT_CONSISTENCY_DECLARE_NUMTRAITS(
double)
483LASS_NUM_FLOATING_POINT_CONSISTENCY_DECLARE_NUMTRAITS(
long double)
485template<
class T>
inline
486bool isNaN(
const Consistent<T>& v )
488 return num::isNaN(v.value());
491template <
typename T,
typename Char,
typename Traits>
492std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& s,
const Consistent<T>& v)
498template <
typename T,
typename Char,
typename Traits>
499std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& s, Consistent<T>& v)
503 v = Consistent<T>(temp);
515void swap(::lass::num::Consistent<T>& a, ::lass::num::Consistent<T>& b)
T inv(const T &x)
return x ^ -1
T pow(const T &x, const T &p)
return exp(p * log(x));
T abs(const T &x)
if x < 0 return -x, else return x.
numeric types and traits.
Library for Assembled Shared Sources.