15 #ifndef INCG_IRIS_IUTEST_DEFS_HPP_839F06DB_E0B6_4E6A_84F2_D99C0A44E06C_
16 #define INCG_IRIS_IUTEST_DEFS_HPP_839F06DB_E0B6_4E6A_84F2_D99C0A44E06C_
32 #if IUTEST_HAS_TYPED_TEST_P
33 # if IUTEST_TYPED_TEST_P_STRICT
57 struct TestTypeIdHelper {
public:
static bool _dummy; };
59 template<
typename T>
bool TestTypeIdHelper<T>::_dummy =
false;
70 inline TypeId GetTypeId()
72 return &(helper::TestTypeIdHelper<T>::_dummy);
85 struct TypeWithSize :
public detail::type_fit_t<SIZE> {};
95 struct ieee754_bits_from_mant {};
99 struct ieee754_bits_from_mant<11>
111 struct ieee754_bits_from_mant<24>
123 struct ieee754_bits_from_mant<53>
135 struct ieee754_bits_from_mant<64>
147 struct ieee754_bits_from_mant<106>
159 struct ieee754_bits_from_mant<113>
174 struct ieee754_bits : ieee754_bits_from_mant< ::std::numeric_limits<T>::digits > {};
176 #if IUTEST_HAS_FLOAT128
178 struct ieee754_bits<__float128> : ieee754_bits_from_mant<IUTEST_FLT128_MANT_DIG> {};
186 template<
typename RawType>
191 typedef typename detail::type_fit_t<
sizeof(RawType)> IntType;
194 typedef typename IntType::Int Int;
195 typedef typename IntType::UInt UInt;
196 typedef RawType Float;
237 if(
is_nan() || rhs.is_nan() )
251 const UInt v2 = norm(rhs.enable_bits());
252 const UInt diff = (v1 > v2) ? v1 - v2 : v2 - v1;
253 const UInt kMaxUlps = 4u;
254 if( diff <= kMaxUlps )
265 bool AlmostNear(
const _Myt& rhs, RawType max_abs_error)
const
267 if(
is_nan() || rhs.is_nan() )
271 IUTEST_PRAGMA_WARN_PUSH()
272 IUTEST_PRAGMA_WARN_DISABLE_FLOAT_EQUAL()
273 if( m_v.fv == rhs.m_v.fv )
277 IUTEST_PRAGMA_WARN_POP()
279 if( abs.m_v.fv <= max_abs_error )
283 _Myt abs_error =
_Myt(max_abs_error);
295 if(
is_nan() && rhs.is_nan() )
303 _Myt Abs(
const _Myt& rhs)
const
305 if( m_v.fv > rhs.m_v.fv )
307 return _Myt(m_v.fv - rhs.m_v.fv);
311 return _Myt(rhs.m_v.fv - m_v.fv);
318 UInt
bits()
const {
return m_v.uv; }
323 UInt
enable_bits()
const {
return m_v.uv & kEnableBitMask; }
328 RawType
raw()
const {
return m_v.fv; }
353 UInt
sign_bit()
const {
return m_v.uv & kSignMask; }
370 f.m_v.uv = kExpMask | kDefaultMantBitMask;
377 f.m_v.uv |= kSignMask;
384 f.m_v.uv = kExpMask | kDefaultMantBitMask | 1;
391 f.m_v.uv |= kSignMask;
398 f.m_v.uv = ((1 << (kEXP + 1)) - 1);
399 f.m_v.uv <<= kMANT - 1;
400 f.m_v.uv |= kDefaultMantBitMask;
407 f.m_v.uv |= kSignMask;
412 #if !defined(_MSC_VER) || _MSC_VER >= 1310
413 operator RawType ()
const {
return m_v.fv; }
415 operator float()
const {
return m_v.fv; }
416 operator double()
const {
return m_v.fv; }
418 _Myt&
operator = (RawType f) { m_v.fv = f;
return *
this; }
426 static const int kEXP;
427 static const int kMANT;
428 static const int kDIGITS;
431 static UInt norm(UInt v) {
return (v & kSignMask) ? (~v + 1) : (v | kSignMask); }
433 static const UInt kSignMask;
434 static const UInt kExpMask;
435 static const UInt kMantMask;
436 static const UInt kEconomizedMantMask;
437 static const UInt kDefaultMantBitMask;
438 static const UInt kEnableBitMask;
445 const int floating_point<T>::kEXP = detail::ieee754_bits<T>::EXP;
447 const int floating_point<T>::kMANT = detail::ieee754_bits<T>::MANT;
449 const int floating_point<T>::kDIGITS = detail::ieee754_bits<T>::MANT + detail::ieee754_bits<T>::MANT_HIDDEN;
452 const typename floating_point<T>::UInt floating_point<T>::kSignMask
453 =
static_cast<typename floating_point<T>::UInt
>(1u) << (kEXP + kMANT);
455 const typename floating_point<T>::UInt floating_point<T>::kExpMask
456 = ((
static_cast<typename floating_point<T>::UInt
>(1u)
457 << floating_point<T>::kEXP) - 1) << floating_point<T>::kMANT;
459 const typename floating_point<T>::UInt floating_point<T>::kMantMask
460 = ((
static_cast<typename floating_point<T>::UInt
>(1u) << floating_point<T>::kMANT) - 1);
462 const typename floating_point<T>::UInt floating_point<T>::kEconomizedMantMask
463 = ((
static_cast<typename floating_point<T>::UInt
>(1u) << (floating_point<T>::kDIGITS - 1)) - 1);
465 const typename floating_point<T>::UInt floating_point<T>::kDefaultMantBitMask
466 = (
static_cast<typename floating_point<T>::UInt
>(1u) << (floating_point<T>::kDIGITS - 1));
468 const typename floating_point<T>::UInt floating_point<T>::kEnableBitMask
469 = floating_point<T>::kSignMask | floating_point<T>::kExpMask | floating_point<T>::kMantMask;
477 class FloatingPoint :
public floating_point<T>
480 explicit FloatingPoint(
const T& rhs) : floating_point<T>(rhs) {}
483 typedef FloatingPoint<float> Float;
484 typedef FloatingPoint<double> Double;
486 #if IUTEST_HAS_LONG_DOUBLE
487 typedef FloatingPoint<long double> LongDouble;
489 #if IUTEST_HAS_FLOAT128
490 typedef FloatingPoint<__float128> Float128;
497 typedef detail::type_fit_t<1>::Int
Int8;
498 typedef detail::type_fit_t<1>::UInt
UInt8;
499 typedef detail::type_fit_t<2>::Int
Int16;
500 typedef detail::type_fit_t<2>::UInt
UInt16;
501 typedef detail::type_fit_t<4>::Int
Int32;
502 typedef detail::type_fit_t<4>::UInt
UInt32;
503 typedef detail::type_fit_t<8>::Int
Int64;
504 typedef detail::type_fit_t<8>::UInt
UInt64;
506 #if IUTEST_HAS_CXX11 && IUTEST_HAS_CXX_HDR_CSTDINT
507 typedef ::std::intmax_t iu_off_t;
508 typedef ::std::uintmax_t iu_uint_max_t;
510 typedef Int64 iu_off_t;
511 typedef UInt64 iu_uint_max_t;
514 #if IUTEST_HAS_CXX11 && IUTEST_HAS_CXX_HDR_CSTDINT
515 typedef ::std::uintptr_t iu_uintptr_t;
517 typedef detail::type_fit_t<
sizeof(ptrdiff_t)>::UInt iu_uintptr_t;
浮動小数点数
Definition: iutest_defs.hpp:189
UInt economized_mantissa_bits() const
economized mantissa
Definition: iutest_defs.hpp:349
static _Myt PNAN()
plus nan
Definition: iutest_defs.hpp:382
UInt sign_bit() const
sign
Definition: iutest_defs.hpp:354
static _Myt NNAN()
minus nan
Definition: iutest_defs.hpp:389
bool AlmostEquals(const _Myt &rhs) const
浮動小数点数がほぼ一致するかどうか
Definition: iutest_defs.hpp:236
bool NanSensitiveAlmostEquals(const _Myt &rhs) const
浮動小数点数がほぼ一致するかどうか
Definition: iutest_defs.hpp:249
UInt bits() const
ビット列の取得
Definition: iutest_defs.hpp:319
bool operator==(RawType rhs) const
比較
Definition: iutest_defs.hpp:422
UInt exponent_bits() const
exponent
Definition: iutest_defs.hpp:334
UInt enable_bits() const
ビット列の取得
Definition: iutest_defs.hpp:324
floating_point()
コンストラクタ
Definition: iutest_defs.hpp:209
bool AlmostNear(const _Myt &rhs, RawType max_abs_error) const
浮動小数点数の差分が max_abs_error 以内に収まるかどうか
Definition: iutest_defs.hpp:266
RawType raw() const
raw データの取得
Definition: iutest_defs.hpp:329
bool NanSensitiveAlmostNear(const _Myt &rhs, RawType max_abs_error) const
浮動小数点数の差分が max_abs_error 以内に収まるかどうか
Definition: iutest_defs.hpp:294
static _Myt PINF()
plus inf
Definition: iutest_defs.hpp:368
bool is_nan() const
is nan
Definition: iutest_defs.hpp:359
UInt fraction_bits() const
fraction (mantissa)
Definition: iutest_defs.hpp:339
static _Myt NQNAN()
minus qnan
Definition: iutest_defs.hpp:405
static _Myt PQNAN()
plus qnan
Definition: iutest_defs.hpp:396
bool is_inf() const
is inf
Definition: iutest_defs.hpp:364
static _Myt NINF()
minus inf
Definition: iutest_defs.hpp:375
UInt mantissa_bits() const
mantissa
Definition: iutest_defs.hpp:344
_Myt & operator=(RawType f)
代入
Definition: iutest_defs.hpp:419
iris unit test compiler 依存の吸収 ファイル
#define IUTEST_CXX_CONSTEXPR
constexpr
Definition: iutest_compiler.hpp:372
iris unit test debug 用定義 ファイル
iutest root namespace
Definition: iutest_charcode.hpp:33
detail::type_fit_t< 1 >::UInt UInt8
8 bit 符号なし整数型
Definition: iutest_defs.hpp:499
detail::type_least_t< 8 >::UInt TimeInMillisec
ミリ秒単位を扱う型
Definition: iutest_defs.hpp:526
detail::type_fit_t< 1 >::Int Int8
8 bit 符号付き整数型
Definition: iutest_defs.hpp:498
void(* SetUpMethod)()
SetUp 関数型
Definition: iutest_defs.hpp:523
void(* TearDownMethod)()
TearDown 関数型
Definition: iutest_defs.hpp:524
detail::type_fit_t< 4 >::UInt UInt32
32 bit 符号なし整数型
Definition: iutest_defs.hpp:503
detail::type_fit_t< 4 >::Int Int32
32 bit 符号付き整数型
Definition: iutest_defs.hpp:502
detail::type_fit_t< 8 >::UInt UInt64
64 bit 符号なし整数型
Definition: iutest_defs.hpp:505
detail::type_fit_t< 2 >::Int Int16
16 bit 符号付き整数型
Definition: iutest_defs.hpp:500
detail::type_fit_t< 8 >::Int Int64
64 bit 符号付き整数型
Definition: iutest_defs.hpp:504
internal::TypeId TestTypeId
テスト識別型
Definition: iutest_defs.hpp:521
detail::type_least_t< 8 >::Int BiggestInt
Biggest Int
Definition: iutest_defs.hpp:527
detail::type_fit_t< 2 >::UInt UInt16
16 bit 符号なし整数型
Definition: iutest_defs.hpp:501
Definition: iutest_defs.hpp:199