📄 mwutil.h
字号:
#if defined(MSWIND)
#define utNEZero(x) (((x) < 0.0) || ((x) > 0.0))
#define utEQZero(x) (((x) >= 0.0) && ((x) <= 0.0))
#define utLTZero(x) (((x) < 0.0) && !utIsNaN(x))
#define utLEZero(x) (((x) <= 0.0) && !utIsNaN(x))
#else
#define utNEZero(x) ((x) != 0.0)
#define utEQZero(x) ((x) == 0.0)
#define utLTZero(x) ((x) < 0.0)
#define utLEZero(x) ((x) <= 0.0)
#endif
/* Since the > and >= are correct for the NaN case it is
* outside the ifdef code. Cleve and I decided to add them
* to maintain the consistency of syntax.
*/
#define utGTZero(x) ((x) > 0.0)
#define utGEZero(x) ((x) >= 0.0)
/*
* Predicate to determine whether a double is an int.
* -0 is not considered an int, because converting it back
* does not yield the same double.
*/
extern bool utDblIsInt(double x);
/*
* Use unique NaNs as flags for special values
* These values should never be generated by Matlab as valid NaNs.
*
* The low-order word is all zeros.
*/
#define UT_SPECIAL_NAN 0x7ff5c5c0
#define UT_NAN_NEVER_TOUCHED (UT_SPECIAL_NAN + 0x1)
#define UT_NAN_FORLOOP_EMPTY (UT_SPECIAL_NAN + 0x2)
#define UT_SET_NAN_VALUE(lval, jqnan) ut_SET_BOTH(lval, jqnan, 0)
/*
* since the x86 fpu can change the leading mastissa bit on QNaNs, we check for
* equality with and without the bit set.
*/
#define UT_QNAN_BITMASK 0x00080000
#define UT_IS_NAN_VALUE(val, jqnan) \
(*(((int*)&(val))+(CPU_NUM_FORMAT==FIEEE_BE)) == 0x0 && \
(*(((int*)&(val))+(CPU_NUM_FORMAT==FIEEE_LE))|UT_QNAN_BITMASK) == ((jqnan)|UT_QNAN_BITMASK))
# define utAssert(test) /* do nothing */
# define utAssertStr(test, message) /* do nothing */
# define utAssertAlways(message) /* do nothing */
#include "tmwtypes.h"
#ifndef CPU_NUM_FORMAT
#if defined(_M_IX86) || defined(__i386__) || defined(__alpha) || defined(WIN32) || defined(WIN64) || defined(_MSC_VER)
#define CPU_NUM_FORMAT FIEEE_LE
#else
#define CPU_NUM_FORMAT FIEEE_BE
#endif /* if defined */
#endif /* if ndef CPU */
#define FIEEE_LE 0
#define FIEEE_BE 1
#define FVAXD 2
#define FVAXG 3
#define FCRAY 4
#define UNKNOWN 5
#if CPU_NUM_FORMAT==FIEEE_LE
/* Little-endian */
typedef union
{
double value;
struct { uint32_T lw;
uint32_T hw;
} words;
} ieee_double_T;
#elif CPU_NUM_FORMAT==FIEEE_BE
/* Big-endian */
typedef union
{
double value;
struct { uint32_T hw;
uint32_T lw;
} words;
} ieee_double_T;
#else
#error CPU_NUM_FORMAT must be FIEEE_LE or FIEEE_BE
#endif
/*
* Function that returns IEEE infinity
*/
extern double utGetInf(void);
/*
* Function that returns IEEE -infinity
*/
extern double utGetMinusInf(void);
/*
* Function that returns IEEE nan inderterminate
*/
extern double utGetNaN(void);
/*
* Function that returns Eps value
*/
extern double utGetEps(void);
/*
* Function that returns PI value
*/
extern double utGetPI(void);
#ifdef __cplusplus
/*
* Query Functions
*/
/*
* Is this double a NaN? function
*/
inline bool utIsNaN(double a)
{ /* Begin utIsNaN */
#if defined(_MSC_VER) || defined(__BORLANDC__)
ieee_double_T tem;
tem.value = a;
return (bool)((((tem.words.hw & 0x7fffffff) == 0x7ff00000) && (tem.words.lw != 0))
|| ((tem.words.hw == 0xfff80000) && (tem.words.lw == 0)));
#else
return (bool)((a) != (a));
#endif /* if MSC_VER */
} /* End utIsNaN */
/*
* Is this double infinite? function
*/
inline bool utIsInf(double a)
{ /* Begin utIsInf */
ieee_double_T tem;
tem.value = a;
return (bool) (((tem.words.hw & 0x7fffffff) == 0x7ff00000) &&\
( tem.words.lw == 0));
}/* End utIsInf */
/*
* Is this double plus infinity? function
*/
inline bool utIsPlusInf(double a)
{ /* Begin utIsPlusInf */
ieee_double_T tem;
tem.value = a;
return (bool) ((tem.words.hw == 0x7ff00000) && ( tem.words.lw == 0));
}/* End utIsPlusInf */
/*
* Is this double minus infinity? function
*/
inline bool utIsMinusInf(double a)
{ /* Begin utIsMinusInf */
ieee_double_T tem;
tem.value = a;
return (bool) ((tem.words.hw == 0xfff00000) && ( tem.words.lw == 0));
} /* End utIsMinusInf */
#else
/*
* Is this double a NaN? function
*/
extern bool utIsNaN(double a);
/*
* Is this double infinite? function
*/
extern bool utIsInf(double a);
/*
* Is this double plus infinity? function
*/
extern bool utIsPlusInf(double a);
/*
* Is this double minus infinity? function
*/
extern bool utIsMinusInf(double a);
#endif
#ifdef _MSC_VER
#pragma warning( disable : 4514 ) /* unreferenced inline function has been removed */
#pragma warning( disable : 4035 ) /* no return value for utIsNaN */
#if _MSC_VER > 1100
__forceinline bool utIsNaNW(double a)
{
__asm fld a
__asm fcomp st(0)
__asm fnstsw ax
__asm and eax,0x100
__asm shr eax,8
}
__forceinline bool utIsInfW(double a)
{
__asm fld a
__asm fxam
__asm fnstsw ax
__asm fstp st(0)
__asm and eax,0x500
__asm shr eax,2
__asm shr al,6
__asm and al,ah
}
#else
__inline bool utIsNaNW(double a)
{
__asm fld a
__asm fcomp st(0)
__asm fnstsw ax
__asm and eax,0x100
__asm shr eax,8
}
__inline bool utIsInfW(double a)
{
__asm fld a
__asm fxam
__asm fnstsw ax
__asm fstp st(0)
__asm and eax,0x500
__asm shr eax,2
__asm shr al,6
__asm and al,ah
}
#endif /* if > 1000 */
#define utIsNaN(a) utIsNaNW(a)
#define utIsInf(a) utIsInfW(a)
#endif
#if (!defined( _MSC_VER ) && !defined(__BORLANDC__))
#define utIsNaN(a) ((bool)((a) != (a)))
#endif /* _MSC_VER */
/* fix(a) */
#define utDoubleScalarFix(a) ((a) < 0.0 ? utFdlibm_ceil(a) : utFdlibm_floor(a))
/* a + b */
#define utDoubleScalarPlus(a,b) ((a) + (b))
/* a - b */
#define utDoubleScalarMinus(a,b) ((a) - (b))
/* -a */
#define utDoubleScalarUminus(a) (-(a))
/* +a */
#define utDoubleScalarUplus(a) (a)
/* a * b */
#define utDoubleScalarTimes(a,b) ((a) * (b))
/* a/b and a./b */
/* A warning 'Divide by zero' should be issued by users for b = 0 */
#define utDoubleScalarRdivide(a,b) ((a)/(b))
/* a\b and a.\b */
/* A warning 'Divide by zero' should be issued by users for a = 0 */
#define utDoubleScalarLdivide(a,b) ((b)/(a))
#ifdef _MSC_VER
/* a < b */
#define utDoubleScalarLt(a,b) (utIsNaN(a) || utIsNaN(b) ? false : ((a) < (b) ))
/* a > b */
#define utDoubleScalarGt(a,b) (utIsNaN(a) || utIsNaN(b) ? false : ((a) > (b) ))
/* a <= b */
#define utDoubleScalarLe(a,b) (utIsNaN(a) || utIsNaN(b) ? false : ((a) <= (b)))
/* a >= b */
#define utDoubleScalarGe(a,b) (utIsNaN(a) || utIsNaN(b) ? false : ((a) >= (b)))
/* eq(a,b) and a == b */
#define utDoubleScalarEq(a,b) (utIsNaN(a) || utIsNaN(b) ? false : ((a) == (b)))
/* a ~= b */
#define utDoubleScalarNe(a,b) (utIsNaN(a) || utIsNaN(b) ? true : ((a) != (b) ))
#else
/* a < b */
#define utDoubleScalarLt(a,b) ((a) < (b) )
/* a > b */
#define utDoubleScalarGt(a,b) ((a) > (b) )
/* a <= b */
#define utDoubleScalarLe(a,b) ((a) <= (b) )
/* a >= b */
#define utDoubleScalarGe(a,b) ((a) >= (b) )
/* a = b */
#define utDoubleScalarEq(a,b) ((a) == (b) )
/* a ~= b */
#define utDoubleScalarNe(a,b) ((a) != (b) )
#endif /* _MSC_VER */
/* a | b */
/* An error message should be issued by users for a or b = NaN */
#define utDoubleScalarOr(a,b) ((a) != 0.0 || (b) != 0.0)
/* ~a */
/* An error message should be issued by users for a or b = NaN */
#define utDoubleScalarNot(a) ((a) == 0.0)
/* a' */
#define utDoubleScalarCtranspose(a) (a)
/* a.' */
#define utDoubleScalarTranspose(a) (a)
/* abs(a) */
#define utDoubleScalarAbs(a) fabs(a)
/* acos(a) */
#define utDoubleScalarAcos(a) utFdlibm_acos(a)
/* acosh(a) */
#define utDoubleScalarAcosh(a) utFdlibm_acosh(a)
/* acot(a) */
#define utDoubleScalarAcot(a) utFdlibm_atan(1.0/(a))
/* ascs(a) */
#define utDoubleScalarAcsc(a) utFdlibm_asin(1.0/(a))
/* ascsh(a) */
#define utDoubleScalarAcsch(a) utFdlibm_asinh(1.0/(a))
/* all(a) */
#define utDoubleScalarAll(a) (utIsNaN(a) || (a != 0.0))
/* a & b */
/* An error message should be issued by users for a or b = NaN */
#define utDoubleScalarAnd(a,b) ((a) != 0.0 && (b) != 0.0)
/* any(a) */
#define utDoubleScalarAny(a) (utIsNaN(a) || (a != 0.0))
/* angle(a) */
#define utDoubleScalarAngle(a) utIsNaN(a) \
? utGetNaN() \
: 0.0+utGetPI()*((a) < 0.0)
/* asec(a) */
#define utDoubleScalarAsec(a) utFdlibm_acos(1.0/(a))
/* asech(a) */
#define utDoubleScalarAsech(a) utFdlibm_acosh(1.0/(a))
/* asin(a) */
#define utDoubleScalarAsin(a) utFdlibm_asin(a)
/* asinh(a) */
#define utDoubleScalarAsinh(a) utFdlibm_asinh(a)
/* atan(a) */
#define utDoubleScalarAtan(a) utFdlibm_atan(a)
/* atan2(a,b) */
#define utDoubleScalarAtan2(a,b) utFdlibm_atan2(a,b)
/* atanh(a) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -