Skip to content

Commit

Permalink
Add definitions for isnan, isinf and isfinite, in case they are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
bel2125 committed Aug 27, 2017
1 parent 2b406f1 commit af96d7f
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/check_check_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,40 @@ double NAN;
#if !defined(INFINITY)
double INFINITY;
#endif
#if !defined(isnan)
int isnan(double d) {

This comment has been minimized.

Copy link
@brarcher

brarcher Aug 29, 2017

This may be good to add to libcompat.h instead. That header deals with defines which may be missing on some platforms, as well as alternative implementations of some methods if they are not available.

#ifdef _MSC_VER
unsigned __int64 *p = &d, m = 0x7FF0000000000000;
#else
unsigned long long *p = &d, m = 0x7FF0000000000000;
#endif
if ((*p & m) != m) return 0; /* finite */
*p &= 0x000FFFFFFFFFFFFF; /* mask exponent and sign */
return *p != 0;
}
#endif
#if !defined(isinf)
int isinf(double d) {
#ifdef _MSC_VER
unsigned __int64 *p = &d, m = 0x7FF0000000000000;
#else
unsigned long long *p = &d, m = 0x7FF0000000000000;
#endif
*p &= 0x000FFFFFFFFFFFFF; /* mask exponent and sign */
return *p == 0;
}
#endif
#if !defined(isfinite)
int isfinite(double d) {
#ifdef _MSC_VER
unsigned __int64 *p = &d, m = 0x7FF0000000000000;
#else
unsigned long long *p = &d, m = 0x7FF0000000000000;
#endif
return (*p & m) != m;
}
#endif


START_TEST(test_lno)
{
Expand Down

0 comments on commit af96d7f

Please sign in to comment.