[詳解]
15 #ifndef INCG_IRIS_IUTEST_DEFS_HPP_839F06DB_E0B6_4E6A_84F2_D99C0A44E06C_
16 #define INCG_IRIS_IUTEST_DEFS_HPP_839F06DB_E0B6_4E6A_84F2_D99C0A44E06C_
29 #if IUTEST_HAS_TYPED_TEST_P
30 # if IUTEST_TYPED_TEST_P_STRICT
54 struct TestTypeIdHelper {
public:
static bool _dummy; };
56 template<
typename T>
bool TestTypeIdHelper<T>::_dummy =
false;
67 inline TypeId GetTypeId()
69 return &(helper::TestTypeIdHelper<T>::_dummy);
82 struct TypeWithSize :
public detail::type_fit_t<SIZE> {};
96 struct ieee754_bits {};
99 struct ieee754_bits<float>
108 struct ieee754_bits<double>
116 #if IUTEST_HAS_LONG_DOUBLE
119 struct ieee754_bits_longdouble {};
122 struct ieee754_bits_longdouble<8u>
132 struct ieee754_bits_longdouble<16u>
141 struct ieee754_bits<long double> : ieee754_bits_longdouble<sizeof(long double)>
152 template<
typename RawType>
159 typedef typename detail::type_fit_t<
sizeof(RawType)> type;
160 typedef typename type::Int Int;
161 typedef typename type::UInt UInt;
202 if(
is_nan() || rhs.is_nan() )
215 const UInt v1 = norm(
bits());
216 const UInt v2 = norm(rhs.bits());
217 const UInt diff = (v1 > v2) ? v1 - v2 : v2 - v1;
218 if( diff <= kMaxUlps )
229 bool AlmostNear(
const _Myt& rhs, RawType max_abs_error)
const
231 if(
is_nan() || rhs.is_nan() )
235 IUTEST_PRAGMA_WARN_PUSH()
236 IUTEST_PRAGMA_WARN_FLOAT_EQUAL()
237 if( m_v.fv == rhs.m_v.fv )
241 IUTEST_PRAGMA_WARN_POP()
243 if( abs.m_v.fv <= max_abs_error )
247 _Myt abs_error =
_Myt(max_abs_error);
259 if(
is_nan() && rhs.is_nan() )
267 _Myt Abs(
const _Myt& rhs)
const
269 if( m_v.fv > rhs.m_v.fv )
271 return _Myt(m_v.fv - rhs.m_v.fv);
275 return _Myt(rhs.m_v.fv - m_v.fv);
282 UInt
bits()
const {
return m_v.uv & kEnableBitMask; }
287 RawType
raw()
const {
return m_v.fv; }
302 UInt
sign_bit()
const {
return m_v.uv & kSignMask; }
326 f.m_v.uv |= kSignMask;
333 f.m_v.uv = kExpMask | 1;
340 f.m_v.uv |= kSignMask;
347 f.m_v.uv = ((1 << (kEXP + 1)) - 1);
348 f.m_v.uv <<= kFRAC - 1;
355 f.m_v.uv |= kSignMask;
360 #if !defined(_MSC_VER) || _MSC_VER >= 1310
361 operator RawType ()
const {
return m_v.fv; }
363 operator float()
const {
return m_v.fv; }
364 operator double()
const {
return m_v.fv; }
366 _Myt& operator = (RawType f) { m_v.fv = f;
return *
this; }
367 _Myt& operator = (
const _Myt& rhs) { m_v.fv = rhs.m_v;
return *
this; }
369 bool operator == (
const _Myt& rhs)
const {
return m_v.uv == rhs.m_v.uv; }
374 kEXP = detail::ieee754_bits<RawType>::EXP
375 , kFRAC = detail::ieee754_bits<RawType>::FRAC
380 static UInt norm(UInt v) {
return (v & kSignMask) ? (~v + 1) : (v | kSignMask); }
382 #if !defined(IUTEST_NO_INCLASS_MEMBER_INITIALIZATION)
383 static const UInt kSignMask =
static_cast<UInt
>(1u) << (kEXP + kFRAC);
384 static const UInt kExpMask = ((
static_cast<UInt
>(1u) << kEXP) - 1) << kFRAC;
385 static const UInt kFracMask = (
static_cast<UInt
>(1u) << kFRAC) - 1;
386 static const UInt kEnableBitMask = kSignMask | kExpMask | kFracMask;
388 static const UInt kSignMask;
389 static const UInt kExpMask;
390 static const UInt kFracMask;
391 static const UInt kEnableBitMask;
398 #if defined(IUTEST_NO_INCLASS_MEMBER_INITIALIZATION)
401 const typename floating_point<T>::UInt floating_point<T>::kSignMask
402 =
static_cast<typename floating_point<T>::UInt
>(1u) << (kEXP + kFRAC);
404 const typename floating_point<T>::UInt floating_point<T>::kExpMask
405 = ((
static_cast<typename floating_point<T>::UInt
>(1u)
406 << floating_point<T>::kEXP) - 1) << floating_point<T>::kFRAC;
408 const typename floating_point<T>::UInt floating_point<T>::kFracMask
409 = ((
static_cast<typename floating_point<T>::UInt
>(1u) << floating_point<T>::kFRAC) - 1);
411 const typename floating_point<T>::UInt floating_point<T>::kEnableBitMask
412 = floating_point<T>::kSignMask | floating_point<T>::kExpMask | floating_point<T>::kFracMask;
418 typedef detail::type_fit_t<1>::Int
Int8;
419 typedef detail::type_fit_t<1>::UInt
UInt8;
420 typedef detail::type_fit_t<2>::Int
Int16;
421 typedef detail::type_fit_t<2>::UInt
UInt16;
422 typedef detail::type_fit_t<4>::Int
Int32;
423 typedef detail::type_fit_t<4>::UInt
UInt32;
424 typedef detail::type_fit_t<8>::Int
Int64;
425 typedef detail::type_fit_t<8>::UInt
UInt64;
427 #if IUTEST_HAS_CXX11 && IUTEST_HAS_CXX_HDR_CSTDINT
428 typedef ::std::uintmax_t iu_off_t;
433 #if IUTEST_HAS_CXX11 && IUTEST_HAS_CXX_HDR_CSTDINT
434 typedef ::std::uintptr_t iu_uintptr_t;
436 typedef detail::type_fit_t<
sizeof(ptrdiff_t)>::UInt iu_uintptr_t;
484 #endif // INCG_IRIS_IUTEST_DEFS_HPP_839F06DB_E0B6_4E6A_84F2_D99C0A44E06C_
detail::type_fit_t< 2 >::Int Int16
16 bit 符号付き整数型
Definition: iutest_defs.hpp:421
UInt fraction_bits() const
fraction
Definition: iutest_defs.hpp:298
bool is_inf() const
is inf
Definition: iutest_defs.hpp:313
bool NanSensitiveAlmostNear(const _Myt &rhs, RawType max_abs_error) const
浮動小数点数の差分が max_abs_error 以内に収まるかどうか
Definition: iutest_defs.hpp:258
bool AlmostNear(const _Myt &rhs, RawType max_abs_error) const
浮動小数点数の差分が max_abs_error 以内に収まるかどうか
Definition: iutest_defs.hpp:230
bool is_nan() const
is nan
Definition: iutest_defs.hpp:308
bool AlmostEquals(const _Myt &rhs) const
浮動小数点数がほぼ一致するかどうか
Definition: iutest_defs.hpp:201
floating_point(RawType f)
コンストラクタ
Definition: iutest_defs.hpp:183
bool NanSensitiveAlmostEquals(const _Myt &rhs) const
浮動小数点数がほぼ一致するかどうか
Definition: iutest_defs.hpp:214
UInt sign_bit() const
sign
Definition: iutest_defs.hpp:303
detail::type_fit_t< 2 >::UInt UInt16
16 bit 符号なし整数型
Definition: iutest_defs.hpp:422
iutest root namespace
Definition: iutest_charcode.hpp:31
iris unit test debug 用定義 ファイル
detail::type_fit_t< 8 >::Int Int64
64 bit 符号付き整数型
Definition: iutest_defs.hpp:425
detail::type_fit_t< 1 >::UInt UInt8
8 bit 符号なし整数型
Definition: iutest_defs.hpp:420
static _Myt PNAN()
plus nan
Definition: iutest_defs.hpp:331
detail::type_fit_t< 8 >::UInt UInt64
64 bit 符号なし整数型
Definition: iutest_defs.hpp:426
static _Myt PINF()
plus inf
Definition: iutest_defs.hpp:317
static _Myt NINF()
minus inf
Definition: iutest_defs.hpp:324
#define IUTEST_CXX_CONSTEXPR
constexpr
Definition: iutest_compiler.hpp:298
floating_point()
コンストラクタ
Definition: iutest_defs.hpp:174
internal::TypeId TestTypeId
テスト識別型
Definition: iutest_defs.hpp:440
static _Myt NNAN()
minus nan
Definition: iutest_defs.hpp:338
detail::type_fit_t< 4 >::Int Int32
32 bit 符号付き整数型
Definition: iutest_defs.hpp:423
RawType raw() const
raw データの取得
Definition: iutest_defs.hpp:288
detail::type_least_t< 8 >::UInt TimeInMillisec
ミリ秒単位を扱う型
Definition: iutest_defs.hpp:445
void(* TearDownMethod)()
TearDown 関数型
Definition: iutest_defs.hpp:443
iris unit test compiler 依存の吸収 ファイル
detail::type_fit_t< 4 >::UInt UInt32
32 bit 符号なし整数型
Definition: iutest_defs.hpp:424
浮動小数点数
Definition: iutest_defs.hpp:154
void(* SetUpMethod)()
SetUp 関数型
Definition: iutest_defs.hpp:442
static _Myt PQNAN()
plus qnan
Definition: iutest_defs.hpp:345
detail::type_least_t< 8 >::Int BiggestInt
Biggest Int
Definition: iutest_defs.hpp:446
UInt exponent_bits() const
exponent
Definition: iutest_defs.hpp:293
static _Myt NQNAN()
minus qnan
Definition: iutest_defs.hpp:353
floating_point(const floating_point &rhs)
コンストラクタ
Definition: iutest_defs.hpp:192
detail::type_fit_t< 1 >::Int Int8
8 bit 符号付き整数型
Definition: iutest_defs.hpp:419
UInt bits() const
ビット列の取得
Definition: iutest_defs.hpp:283