libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

denorm_min.pass.cpp (1925B)


      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // test numeric_limits
     11 
     12 // denorm_min()
     13 
     14 #include <limits>
     15 #include <cfloat>
     16 #include <cassert>
     17 
     18 #include "test_macros.h"
     19 
     20 template <class T>
     21 void
     22 test(T expected)
     23 {
     24     assert(std::numeric_limits<T>::denorm_min() == expected);
     25     assert(std::numeric_limits<const T>::denorm_min() == expected);
     26     assert(std::numeric_limits<volatile T>::denorm_min() == expected);
     27     assert(std::numeric_limits<const volatile T>::denorm_min() == expected);
     28 }
     29 
     30 int main()
     31 {
     32     test<bool>(false);
     33     test<char>(0);
     34     test<signed char>(0);
     35     test<unsigned char>(0);
     36     test<wchar_t>(0);
     37 #if TEST_STD_VER > 17 && defined(__cpp_char8_t)
     38     test<char8_t>(0);
     39 #endif
     40 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
     41     test<char16_t>(0);
     42     test<char32_t>(0);
     43 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
     44     test<short>(0);
     45     test<unsigned short>(0);
     46     test<int>(0);
     47     test<unsigned int>(0);
     48     test<long>(0);
     49     test<unsigned long>(0);
     50     test<long long>(0);
     51     test<unsigned long long>(0);
     52 #ifndef _LIBCPP_HAS_NO_INT128
     53     test<__int128_t>(0);
     54     test<__uint128_t>(0);
     55 #endif
     56 #if defined(__FLT_DENORM_MIN__) // guarded because these macros are extensions.
     57     test<float>(__FLT_DENORM_MIN__);
     58     test<double>(__DBL_DENORM_MIN__);
     59     test<long double>(__LDBL_DENORM_MIN__);
     60 #endif
     61 #if defined(FLT_TRUE_MIN) // not currently provided on linux.
     62     test<float>(FLT_TRUE_MIN);
     63     test<double>(DBL_TRUE_MIN);
     64     test<long double>(LDBL_TRUE_MIN);
     65 #endif
     66 #if !defined(__FLT_DENORM_MIN__) && !defined(FLT_TRUE_MIN)
     67 #error Test has no expected values for floating point types
     68 #endif
     69 }