http://llvm.org/bugs/show_bug.cgi?id=9854. Also created an emulated hexfloat literal for use in some of the tests. <sigh> And cleaned up some harmless but irritating warnings in the tests.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@131318 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant 2011-05-13 21:52:40 +00:00
parent 11a58a68e1
commit 0a111118a6
9 changed files with 461 additions and 426 deletions

View File

@ -303,8 +303,340 @@ long double truncl(long double x);
#pragma GCC system_header
// signbit
#ifdef signbit
template <class _A1>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_signbit(_A1 __x)
{
return signbit(__x);
}
#undef signbit
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
signbit(_A1 __x)
{
return __libcpp_signbit(__x);
}
#endif // signbit
// fpclassify
#ifdef fpclassify
template <class _A1>
_LIBCPP_ALWAYS_INLINE
int
__libcpp_fpclassify(_A1 __x)
{
return fpclassify(__x);
}
#undef fpclassify
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_floating_point<_A1>::value, int>::type
fpclassify(_A1 __x)
{
return __libcpp_fpclassify(__x);
}
#endif // fpclassify
// isfinite
#ifdef isfinite
template <class _A1>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_isfinite(_A1 __x)
{
return isfinite(__x);
}
#undef isfinite
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
isfinite(_A1 __x)
{
return __libcpp_isfinite(__x);
}
#endif // isfinite
// isinf
#ifdef isinf
template <class _A1>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_isinf(_A1 __x)
{
return isinf(__x);
}
#undef isinf
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
isinf(_A1 __x)
{
return __libcpp_isinf(__x);
}
#endif // isinf
// isnan
#ifdef isnan
template <class _A1>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_isnan(_A1 __x)
{
return isnan(__x);
}
#undef isnan
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
isnan(_A1 __x)
{
return __libcpp_isnan(__x);
}
#endif // isnan
// isnormal
#ifdef isnormal
template <class _A1>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_isnormal(_A1 __x)
{
return isnormal(__x);
}
#undef isnormal
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
isnormal(_A1 __x)
{
return __libcpp_isnormal(__x);
}
#endif // isnormal
// isgreater
#ifdef isgreater
template <class _A1, class _A2>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_isgreater(_A1 __x, _A2 __y)
{
return isgreater(__x, __y);
}
#undef isgreater
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if
<
std::is_floating_point<_A1>::value &&
std::is_floating_point<_A2>::value,
bool
>::type
isgreater(_A1 __x, _A2 __y)
{
return __libcpp_isgreater(__x, __y);
}
#endif // isgreater
// isgreaterequal
#ifdef isgreaterequal
template <class _A1, class _A2>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_isgreaterequal(_A1 __x, _A2 __y)
{
return isgreaterequal(__x, __y);
}
#undef isgreaterequal
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if
<
std::is_floating_point<_A1>::value &&
std::is_floating_point<_A2>::value,
bool
>::type
isgreaterequal(_A1 __x, _A2 __y)
{
return __libcpp_isgreaterequal(__x, __y);
}
#endif // isgreaterequal
// isless
#ifdef isless
template <class _A1, class _A2>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_isless(_A1 __x, _A2 __y)
{
return isless(__x, __y);
}
#undef isless
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if
<
std::is_floating_point<_A1>::value &&
std::is_floating_point<_A2>::value,
bool
>::type
isless(_A1 __x, _A2 __y)
{
return __libcpp_isless(__x, __y);
}
#endif // isless
// islessequal
#ifdef islessequal
template <class _A1, class _A2>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_islessequal(_A1 __x, _A2 __y)
{
return islessequal(__x, __y);
}
#undef islessequal
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if
<
std::is_floating_point<_A1>::value &&
std::is_floating_point<_A2>::value,
bool
>::type
islessequal(_A1 __x, _A2 __y)
{
return __libcpp_islessequal(__x, __y);
}
#endif // islessequal
// islessgreater
#ifdef islessgreater
template <class _A1, class _A2>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_islessgreater(_A1 __x, _A2 __y)
{
return islessgreater(__x, __y);
}
#undef islessgreater
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if
<
std::is_floating_point<_A1>::value &&
std::is_floating_point<_A2>::value,
bool
>::type
islessgreater(_A1 __x, _A2 __y)
{
return __libcpp_islessgreater(__x, __y);
}
#endif // islessgreater
// isunordered
#ifdef isunordered
template <class _A1, class _A2>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_isunordered(_A1 __x, _A2 __y)
{
return isunordered(__x, __y);
}
#undef isunordered
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if
<
std::is_floating_point<_A1>::value &&
std::is_floating_point<_A2>::value,
bool
>::type
isunordered(_A1 __x, _A2 __y)
{
return __libcpp_isunordered(__x, __y);
}
#endif // isunordered
_LIBCPP_BEGIN_NAMESPACE_STD
using ::signbit;
using ::fpclassify;
using ::isfinite;
using ::isinf;
using ::isnan;
using ::isnormal;
using ::isgreater;
using ::isgreaterequal;
using ::isless;
using ::islessequal;
using ::islessgreater;
using ::isunordered;
using ::isunordered;
using ::float_t;
using ::double_t;
@ -629,348 +961,6 @@ inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<is_integral<_A1>::value, double>::type
tanh(_A1 __x) {return tanh((double)__x);}
// signbit
#ifndef signbit
#error Implementation error: signbit not defined
#else
template <class _A1>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_signbit(_A1 __x)
{
return signbit(__x);
}
#undef signbit
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<is_floating_point<_A1>::value, bool>::type
signbit(_A1 __x)
{
return __libcpp_signbit(__x);
}
#endif // signbit
// fpclassify
#ifndef fpclassify
#error Implementation error: fpclassify not defined
#else
template <class _A1>
_LIBCPP_ALWAYS_INLINE
int
__libcpp_fpclassify(_A1 __x)
{
return fpclassify(__x);
}
#undef fpclassify
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<is_floating_point<_A1>::value, int>::type
fpclassify(_A1 __x)
{
return __libcpp_fpclassify(__x);
}
#endif // fpclassify
// isfinite
#ifndef isfinite
#error Implementation error: isfinite not defined
#else
template <class _A1>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_isfinite(_A1 __x)
{
return isfinite(__x);
}
#undef isfinite
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<is_floating_point<_A1>::value, bool>::type
isfinite(_A1 __x)
{
return __libcpp_isfinite(__x);
}
#endif // isfinite
// isinf
#ifndef isinf
#error Implementation error: isinf not defined
#else
template <class _A1>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_isinf(_A1 __x)
{
return isinf(__x);
}
#undef isinf
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<is_floating_point<_A1>::value, bool>::type
isinf(_A1 __x)
{
return __libcpp_isinf(__x);
}
#endif // isinf
// isnan
#ifndef isnan
#error Implementation error: isnan not defined
#else
template <class _A1>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_isnan(_A1 __x)
{
return isnan(__x);
}
#undef isnan
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<is_floating_point<_A1>::value, bool>::type
isnan(_A1 __x)
{
return __libcpp_isnan(__x);
}
#endif // isnan
// isnormal
#ifndef isnormal
#error Implementation error: isnormal not defined
#else
template <class _A1>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_isnormal(_A1 __x)
{
return isnormal(__x);
}
#undef isnormal
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<is_floating_point<_A1>::value, bool>::type
isnormal(_A1 __x)
{
return __libcpp_isnormal(__x);
}
#endif // isnormal
// isgreater
#ifndef isgreater
#error Implementation error: isgreater not defined
#else
template <class _A1, class _A2>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_isgreater(_A1 __x, _A2 __y)
{
return isgreater(__x, __y);
}
#undef isgreater
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_floating_point<_A1>::value &&
is_floating_point<_A2>::value,
bool
>::type
isgreater(_A1 __x, _A2 __y)
{
return __libcpp_isgreater(__x, __y);
}
#endif // isgreater
// isgreaterequal
#ifndef isgreaterequal
#error Implementation error: isgreaterequal not defined
#else
template <class _A1, class _A2>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_isgreaterequal(_A1 __x, _A2 __y)
{
return isgreaterequal(__x, __y);
}
#undef isgreaterequal
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_floating_point<_A1>::value &&
is_floating_point<_A2>::value,
bool
>::type
isgreaterequal(_A1 __x, _A2 __y)
{
return __libcpp_isgreaterequal(__x, __y);
}
#endif // isgreaterequal
// isless
#ifndef isless
#error Implementation error: isless not defined
#else
template <class _A1, class _A2>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_isless(_A1 __x, _A2 __y)
{
return isless(__x, __y);
}
#undef isless
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_floating_point<_A1>::value &&
is_floating_point<_A2>::value,
bool
>::type
isless(_A1 __x, _A2 __y)
{
return __libcpp_isless(__x, __y);
}
#endif // isless
// islessequal
#ifndef islessequal
#error Implementation error: islessequal not defined
#else
template <class _A1, class _A2>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_islessequal(_A1 __x, _A2 __y)
{
return islessequal(__x, __y);
}
#undef islessequal
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_floating_point<_A1>::value &&
is_floating_point<_A2>::value,
bool
>::type
islessequal(_A1 __x, _A2 __y)
{
return __libcpp_islessequal(__x, __y);
}
#endif // islessequal
// islessgreater
#ifndef islessgreater
#error Implementation error: islessgreater not defined
#else
template <class _A1, class _A2>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_islessgreater(_A1 __x, _A2 __y)
{
return islessgreater(__x, __y);
}
#undef islessgreater
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_floating_point<_A1>::value &&
is_floating_point<_A2>::value,
bool
>::type
islessgreater(_A1 __x, _A2 __y)
{
return __libcpp_islessgreater(__x, __y);
}
#endif // islessgreater
// isunordered
#ifndef isunordered
#error Implementation error: isunordered not defined
#else
template <class _A1, class _A2>
_LIBCPP_ALWAYS_INLINE
bool
__libcpp_isunordered(_A1 __x, _A2 __y)
{
return isunordered(__x, __y);
}
#undef isunordered
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_floating_point<_A1>::value &&
is_floating_point<_A2>::value,
bool
>::type
isunordered(_A1 __x, _A2 __y)
{
return __libcpp_isunordered(__x, __y);
}
#endif // isunordered
// acosh
using ::acosh;

View File

@ -20,6 +20,7 @@ namespace std
template<class charT> struct char_traits;
template<class T> class allocator;
class ios_base;
template <class charT, class traits = char_traits<charT> > class basic_ios;
template <class charT, class traits = char_traits<charT> > class basic_streambuf;

View File

@ -13,6 +13,8 @@
#include <type_traits>
#include <cassert>
#include "../../hexfloat.h"
void test_acos()
{
static_assert((std::is_same<decltype(acos((double)0)), double>::value), "");
@ -194,9 +196,9 @@ void test_tanh()
void test_signbit()
{
static_assert((std::is_same<decltype(signbit((float)0)), int>::value), "");
static_assert((std::is_same<decltype(signbit((double)0)), int>::value), "");
static_assert((std::is_same<decltype(signbit((long double)0)), int>::value), "");
static_assert((std::is_same<decltype(signbit((float)0)), bool>::value), "");
static_assert((std::is_same<decltype(signbit((double)0)), bool>::value), "");
static_assert((std::is_same<decltype(signbit((long double)0)), bool>::value), "");
assert(signbit(-1.0) == true);
}
@ -210,117 +212,117 @@ void test_fpclassify()
void test_isfinite()
{
static_assert((std::is_same<decltype(isfinite((float)0)), int>::value), "");
static_assert((std::is_same<decltype(isfinite((double)0)), int>::value), "");
static_assert((std::is_same<decltype(isfinite((long double)0)), int>::value), "");
static_assert((std::is_same<decltype(isfinite((float)0)), bool>::value), "");
static_assert((std::is_same<decltype(isfinite((double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isfinite((long double)0)), bool>::value), "");
assert(isfinite(-1.0) == true);
}
void test_isinf()
{
static_assert((std::is_same<decltype(isinf((float)0)), int>::value), "");
static_assert((std::is_same<decltype(isinf((double)0)), int>::value), "");
static_assert((std::is_same<decltype(isinf((long double)0)), int>::value), "");
static_assert((std::is_same<decltype(isinf((float)0)), bool>::value), "");
static_assert((std::is_same<decltype(isinf((double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isinf((long double)0)), bool>::value), "");
assert(isinf(-1.0) == false);
}
void test_isnan()
{
static_assert((std::is_same<decltype(isnan((float)0)), int>::value), "");
static_assert((std::is_same<decltype(isnan((double)0)), int>::value), "");
static_assert((std::is_same<decltype(isnan((long double)0)), int>::value), "");
static_assert((std::is_same<decltype(isnan((float)0)), bool>::value), "");
static_assert((std::is_same<decltype(isnan((double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isnan((long double)0)), bool>::value), "");
assert(isnan(-1.0) == false);
}
void test_isnormal()
{
static_assert((std::is_same<decltype(isnormal((float)0)), int>::value), "");
static_assert((std::is_same<decltype(isnormal((double)0)), int>::value), "");
static_assert((std::is_same<decltype(isnormal((long double)0)), int>::value), "");
static_assert((std::is_same<decltype(isnormal((float)0)), bool>::value), "");
static_assert((std::is_same<decltype(isnormal((double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isnormal((long double)0)), bool>::value), "");
assert(isnormal(-1.0) == true);
}
void test_isgreater()
{
static_assert((std::is_same<decltype(isgreater((float)0, (float)0)), int>::value), "");
static_assert((std::is_same<decltype(isgreater((float)0, (double)0)), int>::value), "");
static_assert((std::is_same<decltype(isgreater((float)0, (long double)0)), int>::value), "");
static_assert((std::is_same<decltype(isgreater((double)0, (float)0)), int>::value), "");
static_assert((std::is_same<decltype(isgreater((double)0, (double)0)), int>::value), "");
static_assert((std::is_same<decltype(isgreater((double)0, (long double)0)), int>::value), "");
static_assert((std::is_same<decltype(isgreater((long double)0, (float)0)), int>::value), "");
static_assert((std::is_same<decltype(isgreater((long double)0, (double)0)), int>::value), "");
static_assert((std::is_same<decltype(isgreater((long double)0, (long double)0)), int>::value), "");
static_assert((std::is_same<decltype(isgreater((float)0, (float)0)), bool>::value), "");
static_assert((std::is_same<decltype(isgreater((float)0, (double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isgreater((float)0, (long double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isgreater((double)0, (float)0)), bool>::value), "");
static_assert((std::is_same<decltype(isgreater((double)0, (double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isgreater((double)0, (long double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isgreater((long double)0, (float)0)), bool>::value), "");
static_assert((std::is_same<decltype(isgreater((long double)0, (double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isgreater((long double)0, (long double)0)), bool>::value), "");
assert(isgreater(-1.0, 0.F) == false);
}
void test_isgreaterequal()
{
static_assert((std::is_same<decltype(isgreaterequal((float)0, (float)0)), int>::value), "");
static_assert((std::is_same<decltype(isgreaterequal((float)0, (double)0)), int>::value), "");
static_assert((std::is_same<decltype(isgreaterequal((float)0, (long double)0)), int>::value), "");
static_assert((std::is_same<decltype(isgreaterequal((double)0, (float)0)), int>::value), "");
static_assert((std::is_same<decltype(isgreaterequal((double)0, (double)0)), int>::value), "");
static_assert((std::is_same<decltype(isgreaterequal((double)0, (long double)0)), int>::value), "");
static_assert((std::is_same<decltype(isgreaterequal((long double)0, (float)0)), int>::value), "");
static_assert((std::is_same<decltype(isgreaterequal((long double)0, (double)0)), int>::value), "");
static_assert((std::is_same<decltype(isgreaterequal((long double)0, (long double)0)), int>::value), "");
static_assert((std::is_same<decltype(isgreaterequal((float)0, (float)0)), bool>::value), "");
static_assert((std::is_same<decltype(isgreaterequal((float)0, (double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isgreaterequal((float)0, (long double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isgreaterequal((double)0, (float)0)), bool>::value), "");
static_assert((std::is_same<decltype(isgreaterequal((double)0, (double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isgreaterequal((double)0, (long double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isgreaterequal((long double)0, (float)0)), bool>::value), "");
static_assert((std::is_same<decltype(isgreaterequal((long double)0, (double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isgreaterequal((long double)0, (long double)0)), bool>::value), "");
assert(isgreaterequal(-1.0, 0.F) == false);
}
void test_isless()
{
static_assert((std::is_same<decltype(isless((float)0, (float)0)), int>::value), "");
static_assert((std::is_same<decltype(isless((float)0, (double)0)), int>::value), "");
static_assert((std::is_same<decltype(isless((float)0, (long double)0)), int>::value), "");
static_assert((std::is_same<decltype(isless((double)0, (float)0)), int>::value), "");
static_assert((std::is_same<decltype(isless((double)0, (double)0)), int>::value), "");
static_assert((std::is_same<decltype(isless((double)0, (long double)0)), int>::value), "");
static_assert((std::is_same<decltype(isless((long double)0, (float)0)), int>::value), "");
static_assert((std::is_same<decltype(isless((long double)0, (double)0)), int>::value), "");
static_assert((std::is_same<decltype(isless((long double)0, (long double)0)), int>::value), "");
static_assert((std::is_same<decltype(isless((float)0, (float)0)), bool>::value), "");
static_assert((std::is_same<decltype(isless((float)0, (double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isless((float)0, (long double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isless((double)0, (float)0)), bool>::value), "");
static_assert((std::is_same<decltype(isless((double)0, (double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isless((double)0, (long double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isless((long double)0, (float)0)), bool>::value), "");
static_assert((std::is_same<decltype(isless((long double)0, (double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isless((long double)0, (long double)0)), bool>::value), "");
assert(isless(-1.0, 0.F) == true);
}
void test_islessequal()
{
static_assert((std::is_same<decltype(islessequal((float)0, (float)0)), int>::value), "");
static_assert((std::is_same<decltype(islessequal((float)0, (double)0)), int>::value), "");
static_assert((std::is_same<decltype(islessequal((float)0, (long double)0)), int>::value), "");
static_assert((std::is_same<decltype(islessequal((double)0, (float)0)), int>::value), "");
static_assert((std::is_same<decltype(islessequal((double)0, (double)0)), int>::value), "");
static_assert((std::is_same<decltype(islessequal((double)0, (long double)0)), int>::value), "");
static_assert((std::is_same<decltype(islessequal((long double)0, (float)0)), int>::value), "");
static_assert((std::is_same<decltype(islessequal((long double)0, (double)0)), int>::value), "");
static_assert((std::is_same<decltype(islessequal((long double)0, (long double)0)), int>::value), "");
static_assert((std::is_same<decltype(islessequal((float)0, (float)0)), bool>::value), "");
static_assert((std::is_same<decltype(islessequal((float)0, (double)0)), bool>::value), "");
static_assert((std::is_same<decltype(islessequal((float)0, (long double)0)), bool>::value), "");
static_assert((std::is_same<decltype(islessequal((double)0, (float)0)), bool>::value), "");
static_assert((std::is_same<decltype(islessequal((double)0, (double)0)), bool>::value), "");
static_assert((std::is_same<decltype(islessequal((double)0, (long double)0)), bool>::value), "");
static_assert((std::is_same<decltype(islessequal((long double)0, (float)0)), bool>::value), "");
static_assert((std::is_same<decltype(islessequal((long double)0, (double)0)), bool>::value), "");
static_assert((std::is_same<decltype(islessequal((long double)0, (long double)0)), bool>::value), "");
assert(islessequal(-1.0, 0.F) == true);
}
void test_islessgreater()
{
static_assert((std::is_same<decltype(islessgreater((float)0, (float)0)), int>::value), "");
static_assert((std::is_same<decltype(islessgreater((float)0, (double)0)), int>::value), "");
static_assert((std::is_same<decltype(islessgreater((float)0, (long double)0)), int>::value), "");
static_assert((std::is_same<decltype(islessgreater((double)0, (float)0)), int>::value), "");
static_assert((std::is_same<decltype(islessgreater((double)0, (double)0)), int>::value), "");
static_assert((std::is_same<decltype(islessgreater((double)0, (long double)0)), int>::value), "");
static_assert((std::is_same<decltype(islessgreater((long double)0, (float)0)), int>::value), "");
static_assert((std::is_same<decltype(islessgreater((long double)0, (double)0)), int>::value), "");
static_assert((std::is_same<decltype(islessgreater((long double)0, (long double)0)), int>::value), "");
static_assert((std::is_same<decltype(islessgreater((float)0, (float)0)), bool>::value), "");
static_assert((std::is_same<decltype(islessgreater((float)0, (double)0)), bool>::value), "");
static_assert((std::is_same<decltype(islessgreater((float)0, (long double)0)), bool>::value), "");
static_assert((std::is_same<decltype(islessgreater((double)0, (float)0)), bool>::value), "");
static_assert((std::is_same<decltype(islessgreater((double)0, (double)0)), bool>::value), "");
static_assert((std::is_same<decltype(islessgreater((double)0, (long double)0)), bool>::value), "");
static_assert((std::is_same<decltype(islessgreater((long double)0, (float)0)), bool>::value), "");
static_assert((std::is_same<decltype(islessgreater((long double)0, (double)0)), bool>::value), "");
static_assert((std::is_same<decltype(islessgreater((long double)0, (long double)0)), bool>::value), "");
assert(islessgreater(-1.0, 0.F) == true);
}
void test_isunordered()
{
static_assert((std::is_same<decltype(isunordered((float)0, (float)0)), int>::value), "");
static_assert((std::is_same<decltype(isunordered((float)0, (double)0)), int>::value), "");
static_assert((std::is_same<decltype(isunordered((float)0, (long double)0)), int>::value), "");
static_assert((std::is_same<decltype(isunordered((double)0, (float)0)), int>::value), "");
static_assert((std::is_same<decltype(isunordered((double)0, (double)0)), int>::value), "");
static_assert((std::is_same<decltype(isunordered((double)0, (long double)0)), int>::value), "");
static_assert((std::is_same<decltype(isunordered((long double)0, (float)0)), int>::value), "");
static_assert((std::is_same<decltype(isunordered((long double)0, (double)0)), int>::value), "");
static_assert((std::is_same<decltype(isunordered((long double)0, (long double)0)), int>::value), "");
static_assert((std::is_same<decltype(isunordered((float)0, (float)0)), bool>::value), "");
static_assert((std::is_same<decltype(isunordered((float)0, (double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isunordered((float)0, (long double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isunordered((double)0, (float)0)), bool>::value), "");
static_assert((std::is_same<decltype(isunordered((double)0, (double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isunordered((double)0, (long double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isunordered((long double)0, (float)0)), bool>::value), "");
static_assert((std::is_same<decltype(isunordered((long double)0, (double)0)), bool>::value), "");
static_assert((std::is_same<decltype(isunordered((long double)0, (long double)0)), bool>::value), "");
assert(isunordered(-1.0, 0.F) == false);
}
@ -528,7 +530,7 @@ void test_nextafter()
static_assert((std::is_same<decltype(nextafter((double)0, (double)0)), double>::value), "");
static_assert((std::is_same<decltype(nextafterf(0,0)), float>::value), "");
static_assert((std::is_same<decltype(nextafterl(0,0)), long double>::value), "");
assert(nextafter(0,1) == 0x1p-1074);
assert(nextafter(0,1) == hexfloat<double>(0x1, 0, -1074));
}
void test_nexttoward()
@ -536,7 +538,7 @@ void test_nexttoward()
static_assert((std::is_same<decltype(nexttoward((double)0, (long double)0)), double>::value), "");
static_assert((std::is_same<decltype(nexttowardf(0, (long double)0)), float>::value), "");
static_assert((std::is_same<decltype(nexttowardl(0, (long double)0)), long double>::value), "");
assert(nexttoward(0, 1) == 0x1p-1074);
assert(nexttoward(0, 1) == hexfloat<double>(0x1, 0, -1074));
}
void test_remainder()

View File

@ -95,19 +95,19 @@ int main()
static_assert((std::is_same<decltype(freopen("", "", fp)), FILE*>::value), "");
static_assert((std::is_same<decltype(setbuf(fp,cp)), void>::value), "");
static_assert((std::is_same<decltype(vfprintf(fp,"",va)), int>::value), "");
static_assert((std::is_same<decltype(fprintf(fp,"")), int>::value), "");
static_assert((std::is_same<decltype(fprintf(fp," ")), int>::value), "");
static_assert((std::is_same<decltype(fscanf(fp,"")), int>::value), "");
static_assert((std::is_same<decltype(printf("")), int>::value), "");
static_assert((std::is_same<decltype(scanf("")), int>::value), "");
static_assert((std::is_same<decltype(snprintf(cp,0,"")), int>::value), "");
static_assert((std::is_same<decltype(sprintf(cp,"")), int>::value), "");
static_assert((std::is_same<decltype(printf("\n")), int>::value), "");
static_assert((std::is_same<decltype(scanf("\n")), int>::value), "");
static_assert((std::is_same<decltype(snprintf(cp,0,"p")), int>::value), "");
static_assert((std::is_same<decltype(sprintf(cp," ")), int>::value), "");
static_assert((std::is_same<decltype(sscanf("","")), int>::value), "");
static_assert((std::is_same<decltype(vfprintf(fp,"",va)), int>::value), "");
static_assert((std::is_same<decltype(vfscanf(fp,"",va)), int>::value), "");
static_assert((std::is_same<decltype(vprintf("",va)), int>::value), "");
static_assert((std::is_same<decltype(vprintf(" ",va)), int>::value), "");
static_assert((std::is_same<decltype(vscanf("",va)), int>::value), "");
static_assert((std::is_same<decltype(vsnprintf(cp,0,"",va)), int>::value), "");
static_assert((std::is_same<decltype(vsprintf(cp,"",va)), int>::value), "");
static_assert((std::is_same<decltype(vsnprintf(cp,0," ",va)), int>::value), "");
static_assert((std::is_same<decltype(vsprintf(cp," ",va)), int>::value), "");
static_assert((std::is_same<decltype(vsscanf("","",va)), int>::value), "");
static_assert((std::is_same<decltype(fgetc(fp)), int>::value), "");
static_assert((std::is_same<decltype(fgets(cp,0,fp)), char*>::value), "");

37
test/hexfloat.h Normal file
View File

@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Define a hexfloat literal emulator since we can't depend on being able to
// for hexfloat literals
// 0x10.F5p-10 == hexfloat<double>(0x10, 0xF5, -10)
#ifndef HEXFLOAT_H
#define HEXFLOAT_H
#include <algorithm>
#include <cmath>
#include <climits>
template <class T>
class hexfloat
{
T value_;
public:
hexfloat(unsigned long long m1, unsigned long long m0, int exp)
{
const std::size_t n = sizeof(unsigned long long) * CHAR_BIT;
value_ = std::ldexp(m1 + std::ldexp(T(m0), -static_cast<int>(n -
std::__clz(m0))), exp);
}
operator T() const {return value_;}
};
#endif

View File

@ -20,6 +20,7 @@
#include <streambuf>
#include <cmath>
#include "iterators.h"
#include "../../../../../hexfloat.h"
typedef std::num_get<char, input_iterator<const char*> > F;
@ -105,7 +106,7 @@ int main()
ios, err, v);
assert(iter.base() == str+sizeof(str)-1);
assert(err == ios.goodbit);
assert(v == 0x125p-1);
assert(v == hexfloat<double>(0x125, 0, -1));
}
{
const char str[] = "inf";

View File

@ -20,6 +20,7 @@
#include <streambuf>
#include <cmath>
#include "iterators.h"
#include "../../../../../hexfloat.h"
typedef std::num_get<char, input_iterator<const char*> > F;
@ -93,7 +94,7 @@ int main()
ios, err, v);
assert(iter.base() == str+sizeof(str)-1);
assert(err == ios.goodbit);
assert(v == 0x125p-1);
assert(v == hexfloat<float>(0x125, 0, -1));
}
{
const char str[] = "inf";

View File

@ -20,6 +20,7 @@
#include <streambuf>
#include <cmath>
#include "iterators.h"
#include "../../../../../hexfloat.h"
typedef std::num_get<char, input_iterator<const char*> > F;
@ -93,7 +94,7 @@ int main()
ios, err, v);
assert(iter.base() == str+sizeof(str)-1);
assert(err == ios.goodbit);
assert(v == 0x125p-1);
assert(v == hexfloat<long double>(0x125, 0, -1));
}
{
const char str[] = "inf";

View File

@ -13,6 +13,8 @@
#include <type_traits>
#include <cassert>
#include "../../hexfloat.h"
void test_abs()
{
static_assert((std::is_same<decltype(std::abs((float)0)), float>::value), "");
@ -1089,7 +1091,7 @@ void test_nextafter()
static_assert((std::is_same<decltype(std::nextafterf(0,0)), float>::value), "");
static_assert((std::is_same<decltype(std::nextafterl(0,0)), long double>::value), "");
static_assert((std::is_same<decltype(std::nextafter((int)0, (int)0)), double>::value), "");
assert(std::nextafter(0,1) == 0x1p-1074);
assert(std::nextafter(0,1) == hexfloat<double>(0x1, 0, -1074));
}
void test_nexttoward()
@ -1107,7 +1109,7 @@ void test_nexttoward()
static_assert((std::is_same<decltype(std::nexttoward((long double)0, (long double)0)), long double>::value), "");
static_assert((std::is_same<decltype(std::nexttowardf(0, (long double)0)), float>::value), "");
static_assert((std::is_same<decltype(std::nexttowardl(0, (long double)0)), long double>::value), "");
assert(std::nexttoward(0, 1) == 0x1p-1074);
assert(std::nexttoward(0, 1) == hexfloat<double>(0x1, 0, -1074));
}
void test_remainder()