testmath.c revision 86b73a2e60103987d3fc86b8d726ba432a86cd4f
/* $Id$ */
/** @file
* Testcase for the no-crt math stuff.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#ifndef MATHTEST_STANDALONE
# include <math.h>
# define printf AssertMsg2
#else
# include <stdio.h>
# include <math.h>
#endif
/* gcc starting with version 4.3 uses the MPFR library which results in more accurate results. gcc-4.3.1 seems to emit the less accurate result. So just allow both results. */
#define SIN180a -0.8011526357338304777463731115L
#define SIN180b -0.801152635733830477871L
static void bitch(const char *pszWhat, const long double *plrdResult, const long double *plrdExpected)
{
const unsigned char *pach1 = (const unsigned char *)plrdResult;
const unsigned char *pach2 = (const unsigned char *)plrdExpected;
#ifndef MATHTEST_STANDALONE
printf("error: %s - %d instead of %d\n", pszWhat, (int)(*plrdResult * 100000), (int)(*plrdExpected * 100000));
#else
printf("error: %s - %.25f instead of %.25f\n", pszWhat, (double)*plrdResult, (double)*plrdExpected);
#endif
printf(" %02x%02x%02x%02x-%02x%02x%02x%02x-%02x%02x\n", pach1[0], pach1[1], pach1[2], pach1[3], pach1[4], pach1[5], pach1[6], pach1[7], pach1[8], pach1[9]);
printf(" %02x%02x%02x%02x-%02x%02x%02x%02x-%02x%02x\n", pach2[0], pach2[1], pach2[2], pach2[3], pach2[4], pach2[5], pach2[6], pach2[7], pach2[8], pach2[9]);
}
{
#if defined(__MINGW32__) && !defined(Assert)
#else
#endif
}
{
}
extern int testsin(void)
{
}
extern int testremainder(void)
{
static double s_rd1 = 2.5;
static double s_rd2 = 2.0;
static double s_rd3 = 0.5;
}
{
}
static __inline__ unsigned get_cw(void)
{
unsigned cw;
return cw & 0xffff;
}
static long double check_lrd(const long double lrd, const unsigned long long ull, const unsigned short us)
{
static volatile long double lrd2;
{
#if defined(__MINGW32__) && !defined(Assert)
printf("%I64x:%04x instead of %I64x:%04x\n", *(unsigned long long *)&lrd2, ((unsigned short *)&lrd2)[4], ull, us);
#else
printf("%llx:%04x instead of %llx:%04x\n", *(unsigned long long *)&lrd2, ((unsigned short *)&lrd2)[4], ull, us);
#endif
__asm__("int3\n");
}
return lrd;
}
{
union
{
long double lrd;
struct
{
unsigned long long ull;
unsigned short us;
} i;
} u;
return u.lrd;
}
static long double check_lrd_cw(const long double lrd, const unsigned long long ull, const unsigned short us, const unsigned cw)
{
{
__asm__("int3\n");
}
}
{
}
extern int testmath(void)
{
unsigned cErrors = 0;
long double lrdResult;
long double lrdExpect;
long double lrd;
do { \
{ \
cErrors++; \
} \
} while (0)
long long llResult;
long long llExpect;
do { \
{ \
cErrors++; \
} \
} while (0)
long lResult;
long lExpect;
do { \
{ \
cErrors++; \
} \
} while (0)
#if !defined(RT_ARCH_AMD64)
#else
#endif
// __asm__("int3");
#if !defined(RT_ARCH_AMD64)
/* c90 says that the constant is 2147483648 (which is not representable as a signed 32-bit
* value). To that constant you've then applied the negation operation. c90 doesn't have
* negative constants, only positive ones that have been negated. */
#endif
set_cw(0x27f);
double rd1 = 44.25;
double rd2 = 34.25;
lrd = 180.0L;
#if 0
#else
{
{
cErrors++;
}
}
#endif
return cErrors;
}
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
#if 0
#define floatx_to_int32 floatx80_to_int32
#define floatx_to_int64 floatx80_to_int64
#define floatx_abs floatx80_abs
#define floatx_chs floatx80_chs
#define floatx_compare floatx80_compare
typedef long double CPU86_LDouble;
typedef union {
long double d;
struct {
unsigned long long lower;
unsigned short upper;
} l;
/* the following deal with x86 long double-precision numbers */
#define MAXEXPD 0x7fff
#define EXPBIAS 16383
typedef long double floatx80;
#define STATUS_PARAM , void *pv
{
return rintl(a);
}
struct myenv
{
unsigned int fpstt; /* top of stack index */
unsigned int fpus;
unsigned int fpuc;
union {
#ifdef USE_X86LDOUBLE
#else
#endif
} fpregs[8];
#define MAXTAN 9223372036854775808.0
static inline void fpush(void)
{
}
static inline void fpop(void)
{
}
static void helper_f2xm1(void)
{
}
static void helper_fyl2x(void)
{
if (fptemp>0.0){
fpop();
} else {
}
}
static void helper_fptan(void)
{
} else {
fpush();
ST0 = 1.0;
/* the above code is for |arg| < 2**52 only */
}
}
static void helper_fpatan(void)
{
fpop();
}
static void helper_fxtract(void)
{
unsigned int expdif;
/*DP exponent bias*/
fpush();
}
static void helper_fprem1(void)
{
int expdif;
int q;
if (expdif < 53) {
q = (int)dblq; /* cutting off top bits is assumed here */
/* (C0,C1,C3) <-- (q2,q1,q0) */
} else {
/* fpsrcop = integer obtained by rounding to the nearest */
}
}
static void helper_fprem(void)
{
#if 0
LogFlow(("helper_fprem: ST0=%.*Vhxs ST1=%.*Vhxs fpus=%#x\n", sizeof(ST0), &ST0, sizeof(ST1), &ST1, env->fpus));
"fldt (%1)\n"
"fprem \n"
"fnstsw (%0)\n"
"fstpt (%1)\n"
"fstpt (%2)\n"
#else
int expdif;
int q;
if ( expdif < 53 ) {
q = (int)dblq; /* cutting off top bits is assumed here */
/* (C0,C1,C3) <-- (q2,q1,q0) */
} else {
/* fpsrcop = integer obtained by chopping */
}
#endif
}
static void helper_fyl2xp1(void)
{
fpop();
} else {
}
}
static void helper_fsqrt(void)
{
if (fptemp<0.0) {
}
}
static void helper_fsincos(void)
{
} else {
fpush();
/* the above code is for |arg| < 2**63 only */
}
}
static void helper_frndint(void)
{
}
static void helper_fscale(void)
{
}
static void helper_fsin(void)
{
} else {
/* the above code is for |arg| < 2**53 only */
}
}
static void helper_fcos(void)
{
} else {
/* the above code is for |arg5 < 2**63 only */
}
}
static void helper_fxam_ST0(void)
{
int expdif;
/* XXX: test fptags too */
#ifdef USE_X86LDOUBLE
#else
#endif
else
} else if (expdif == 0) {
else
} else {
}
}
void check_env(void)
{
int i;
for (i = 0; i < 8; i++)
{
printf("register %i: %#018llx:%#06x\n"
" expected %#018llx:%#06x\n",
i,
}
for (i = 0; i < 8; i++)
}
#endif /* not used. */
#if 0 /* insert this into helper.c */
/* FPU helpers */
unsigned int my_fpstt;
unsigned int my_fpus;
unsigned int my_fpuc;
unsigned char my_fptags[8];
void hlp_fpu_enter(void)
{
int i;
for (i = 0; i < 8; i++)
}
void hlp_fpu_leave(const char *psz)
{
int i;
Log(("/*code*/ \n"));
for (i = 0; i < 8; i++)
Log(("/*code*/ *(unsigned long long *)&env_org.fpregs[%d] = %#018llxULL; ((unsigned short *)&env_org.fpregs[%d])[4] = %#06x; env_org.fptags[%d]=%d;\n",
for (i = 0; i < 8; i++)
{
Log(("/*code*/ *(unsigned long long *)&env_res.fpregs[%d] = %#018llxULL; ((unsigned short *)&env_res.fpregs[%d])[4] = %#06x; env_res.fptags[%d]=%d;\n",
}
Log(("/*code*/ my_env = env_org;\n"));
Log(("/*code*/ check_env();\n"));
}
#endif /* helper.c */
extern void testmath2(void )
{
#if 0
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
#ifdef MATHTEST_STANDALONE
void test_fops(double a, double b)
{
printf("a=%f b=%f a+b=%f\n", a, b, a + b);
printf("a=%f b=%f a-b=%f\n", a, b, a - b);
printf("a=%f b=%f a*b=%f\n", a, b, a * b);
printf("a=%f b=%f a/b=%f\n", a, b, a / b);
/* just to test some op combining */
}
int main()
{
testmath2();
return cErrors;
}
#endif