зеркало из https://github.com/mozilla/gecko-dev.git
Bug 640494 part 2 - Use bit masking instead of signbit() to avoid problems when including some STL headers. r=luke
This commit is contained in:
Родитель
ac73bb36a4
Коммит
cd1ed7b90b
|
@ -41,12 +41,6 @@
|
|||
#define jsnum_h___
|
||||
|
||||
#include <math.h>
|
||||
#if defined(XP_WIN) || defined(XP_OS2)
|
||||
#include <float.h>
|
||||
#endif
|
||||
#ifdef SOLARIS
|
||||
#include <ieeefp.h>
|
||||
#endif
|
||||
#include "jsvalue.h"
|
||||
|
||||
#include "jsstdint.h"
|
||||
|
@ -85,37 +79,32 @@ typedef union jsdpun {
|
|||
jsdouble d;
|
||||
} jsdpun;
|
||||
|
||||
/* Low-level floating-point predicates. See bug 640494. */
|
||||
|
||||
static inline int
|
||||
JSDOUBLE_IS_NaN(jsdouble d)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return _isnan(d);
|
||||
#else
|
||||
return isnan(d);
|
||||
#endif
|
||||
jsdpun u;
|
||||
u.d = d;
|
||||
return (u.u64 & JSDOUBLE_EXPMASK) == JSDOUBLE_EXPMASK &&
|
||||
(u.u64 & JSDOUBLE_MANTMASK) != 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
JSDOUBLE_IS_FINITE(jsdouble d)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return _finite(d);
|
||||
#else
|
||||
return finite(d);
|
||||
#endif
|
||||
/* -0 is finite. NaNs are not. */
|
||||
jsdpun u;
|
||||
u.d = d;
|
||||
return (u.u64 & JSDOUBLE_EXPMASK) != JSDOUBLE_EXPMASK;
|
||||
}
|
||||
|
||||
static inline int
|
||||
JSDOUBLE_IS_INFINITE(jsdouble d)
|
||||
{
|
||||
#ifdef WIN32
|
||||
int c = _fpclass(d);
|
||||
return c == _FPCLASS_NINF || c == _FPCLASS_PINF;
|
||||
#elif defined(SOLARIS)
|
||||
return !finite(d) && !isnan(d);
|
||||
#else
|
||||
return isinf(d);
|
||||
#endif
|
||||
jsdpun u;
|
||||
u.d = d;
|
||||
return (u.u64 & ~JSDOUBLE_SIGNBIT) == JSDOUBLE_EXPMASK;
|
||||
}
|
||||
|
||||
#define JSDOUBLE_HI32_SIGNBIT 0x80000000
|
||||
|
@ -127,13 +116,9 @@ JSDOUBLE_IS_INFINITE(jsdouble d)
|
|||
static inline bool
|
||||
JSDOUBLE_IS_NEG(jsdouble d)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return JSDOUBLE_IS_NEGZERO(d) || d < 0;
|
||||
#elif defined(SOLARIS)
|
||||
return copysign(1, d) < 0;
|
||||
#else
|
||||
return signbit(d);
|
||||
#endif
|
||||
jsdpun u;
|
||||
u.d = d;
|
||||
return (u.s.hi & JSDOUBLE_HI32_SIGNBIT) != 0;
|
||||
}
|
||||
|
||||
static inline uint32
|
||||
|
|
|
@ -89,24 +89,19 @@
|
|||
|
||||
/* To avoid a circular dependency, pull in the necessary pieces of jsnum.h. */
|
||||
|
||||
#include <math.h>
|
||||
#if defined(XP_WIN) || defined(XP_OS2)
|
||||
#include <float.h>
|
||||
#endif
|
||||
#ifdef SOLARIS
|
||||
#include <ieeefp.h>
|
||||
#endif
|
||||
#define JSDOUBLE_SIGNBIT (((uint64) 1) << 63)
|
||||
#define JSDOUBLE_EXPMASK (((uint64) 0x7ff) << 52)
|
||||
#define JSDOUBLE_MANTMASK ((((uint64) 1) << 52) - 1)
|
||||
|
||||
static inline int
|
||||
static JS_ALWAYS_INLINE JSBool
|
||||
JSDOUBLE_IS_NEGZERO(jsdouble d)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return (d == 0 && (_fpclass(d) & _FPCLASS_NZ));
|
||||
#elif defined(SOLARIS)
|
||||
return (d == 0 && copysign(1, d) < 0);
|
||||
#else
|
||||
return (d == 0 && signbit(d));
|
||||
#endif
|
||||
union {
|
||||
jsdouble d;
|
||||
uint64 bits;
|
||||
} x;
|
||||
x.d = d;
|
||||
return x.bits == JSDOUBLE_SIGNBIT;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
|
|
Загрузка…
Ссылка в новой задаче