testmath.c revision 47a77538575bd09436802d2f3d3dcaf1df60b202
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * Testcase for the no-crt math stuff.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync/*******************************************************************************
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync* Header Files *
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync*******************************************************************************/
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync/* 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. */
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsyncstatic void bitch(const char *pszWhat, const long double *plrdResult, const long double *plrdExpected)
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync const unsigned char *pach1 = (const unsigned char *)plrdResult;
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync const unsigned char *pach2 = (const unsigned char *)plrdExpected;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync printf("error: %s - %d instead of %d\n", pszWhat, (int)(*plrdResult * 100000), (int)(*plrdExpected * 100000));
3aad980b92149dd95a1ab72ddb8d11d61a28ace6vboxsync printf("error: %s - %.25f instead of %.25f\n", pszWhat, (double)*plrdResult, (double)*plrdExpected);
3aad980b92149dd95a1ab72ddb8d11d61a28ace6vboxsync 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]);
0a7b20727716a00270f358a1c546473d8c36e8f3vboxsync 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]);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsyncstatic void bitchll(const char *pszWhat, long long llResult, long long llExpected)
0a7b20727716a00270f358a1c546473d8c36e8f3vboxsync printf("error: %s - %I64d instead of %I64d\n", pszWhat, llResult, llExpected);
0a7b20727716a00270f358a1c546473d8c36e8f3vboxsync printf("error: %s - %lld instead of %lld\n", pszWhat, llResult, llExpected);
3aad980b92149dd95a1ab72ddb8d11d61a28ace6vboxsyncstatic void bitchl(const char *pszWhat, long lResult, long lExpected)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync printf("error: %s - %ld instead of %ld\n", pszWhat, lResult, lExpected);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsyncextern int testsin(void)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync return sinl(180.0L) == SIN180a || sinl(180.0L) == SIN180b;
7ccd30dd4bbced565b32c255a11640cd4093abb6vboxsyncextern int testremainder(void)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsyncstatic long double check_lrd(const long double lrd, const unsigned long long ull, const unsigned short us)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync static volatile long double lrd2;
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync printf("%I64x:%04x instead of %I64x:%04x\n", *(unsigned long long *)&lrd2, ((unsigned short *)&lrd2)[4], ull, us);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync printf("%llx:%04x instead of %llx:%04x\n", *(unsigned long long *)&lrd2, ((unsigned short *)&lrd2)[4], ull, us);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsyncstatic long double make_lrd(const unsigned long long ull, const unsigned short us)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync long double lrd;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync unsigned long long ull;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync unsigned short us;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsyncstatic long double check_lrd_cw(const long double lrd, const unsigned long long ull, const unsigned short us, const unsigned cw)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync printf("get_cw() -> %#x expected %#x\n", get_cw(), cw);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsyncstatic long double make_lrd_cw(unsigned long long ull, unsigned short us, unsigned cw)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync return check_lrd_cw(make_lrd(ull, us), ull, us, cw);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsyncextern int testmath(void)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync unsigned cErrors = 0;
660fd430a3a8cfa16505d04c7c577acf89d45a40vboxsync long double lrd;
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync } while (0)
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync } while (0)
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync } while (0)
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECK(atan2l(1.0L, 1.0L), 0.785398163397448309603L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECK(atan2l(2.3L, 3.3L), 0.608689307327411694890L);
7ccd30dd4bbced565b32c255a11640cd4093abb6vboxsync CHECKLL(lrint(-2147483649932412.12343), -2147483648LL);
d605d5391db09e6395a1c091f148f4b86af84bd3vboxsync CHECKLL(lrint(-2147483649932412.12343), -2147483649932412L);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync// __asm__("int $3");
7ccd30dd4bbced565b32c255a11640cd4093abb6vboxsync CHECKL(lrintl(make_lrd_cw(000000000000000000ULL,000000,0x027f)), 0L);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0x3ffe,0x027f)), 0L);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0x3ffe,0x027f)), 0L);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0x3ffe,0x067f)), 0L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0x3ffe,0x067f)), 0L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0x3ffe,0x0a7f)), 1L);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0x3ffe,0x0a7f)), 1L);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0x3ffe,0x0e7f)), 0L);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0x3ffe,0x0e7f)), 0L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0xbffe,0x027f)), 0L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0xbffe,0x027f)), 0L);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0xbffe,0x067f)), -1L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0xbffe,0x067f)), -1L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0xbffe,0x0a7f)), 0L);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0xbffe,0x0a7f)), 0L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0xbffe,0x0e7f)), 0L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0xbffe,0x0e7f)), 0L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0x9249249249249000ULL,0x3ffc,0x027f)), 0L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0x9249249249249000ULL,0x3ffc,0x027f)), 0L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0x9249249249249000ULL,0x3ffc,0x067f)), 0L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0x9249249249249000ULL,0x3ffc,0x067f)), 0L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0x9249249249249000ULL,0x3ffc,0x0a7f)), 1L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0x9249249249249000ULL,0x3ffc,0x0a7f)), 1L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0x9249249249249000ULL,0x3ffc,0x0e7f)), 0L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0x9249249249249000ULL,0x3ffc,0x0e7f)), 0L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0xe38e38e38e38e000ULL,0xbffb,0x027f)), 0L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0xe38e38e38e38e000ULL,0xbffb,0x027f)), 0L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0xe38e38e38e38e000ULL,0xbffb,0x067f)), -1L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0xe38e38e38e38e000ULL,0xbffb,0x067f)), -1L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0xe38e38e38e38e000ULL,0xbffb,0x0a7f)), 0L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0xe38e38e38e38e000ULL,0xbffb,0x0a7f)), 0L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0xe38e38e38e38e000ULL,0xbffb,0x0e7f)), 0L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0xe38e38e38e38e000ULL,0xbffb,0x0e7f)), 0L);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0x400e,0x027f)), 32768L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0x400e,0x027f)), 32768L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0x400e,0x067f)), 32768L);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0x400e,0x067f)), 32768L);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0x400e,0x0a7f)), 32768L);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0x400e,0x0a7f)), 32768L);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0x400e,0x0e7f)), 32768L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync CHECKL(lrintl(make_lrd_cw(0x8000000000000000ULL,0x400e,0x0e7f)), 32768L);
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync /* c90 says that the constant is 2147483648 (which is not representable as a signed 32-bit
65146b9eb3e96dbac286e55faa020bbfd74037d7vboxsync * value). To that constant you've then applied the negation operation. c90 doesn't have
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync * negative constants, only positive ones that have been negated. */
7e10aea6606a51d35041e5a85f9e4f1bd19c4062vboxsync CHECKL(lrintl(make_lrd_cw(0xad78ebc5ac620000ULL,0xc041,0x027f)), (long)(-2147483647L - 1));
e190faad3061288ae099cd3ea8a858bd224c00a7vboxsync CHECKL(lrintl(make_lrd_cw(0xad78ebc5ac620000ULL,0xc041,0x027f)), (long)(-2147483647L - 1));
7e10aea6606a51d35041e5a85f9e4f1bd19c4062vboxsync CHECKL(lrintl(make_lrd_cw(0xad78ebc5ac620000ULL,0xc041,0x067f)), (long)(-2147483647L - 1));
0a79c9258d8fae34fa527f125009ab507561b4edvboxsync CHECKL(lrintl(make_lrd_cw(0xad78ebc5ac620000ULL,0xc041,0x067f)), (long)(-2147483647L - 1));
0a79c9258d8fae34fa527f125009ab507561b4edvboxsync CHECKL(lrintl(make_lrd_cw(0xad78ebc5ac620000ULL,0xc041,0x0a7f)), (long)(-2147483647L - 1));
7e10aea6606a51d35041e5a85f9e4f1bd19c4062vboxsync CHECKL(lrintl(make_lrd_cw(0xad78ebc5ac620000ULL,0xc041,0x0a7f)), (long)(-2147483647L - 1));
7e10aea6606a51d35041e5a85f9e4f1bd19c4062vboxsync CHECKL(lrintl(make_lrd_cw(0xad78ebc5ac620000ULL,0xc041,0x0e7f)), (long)(-2147483647L - 1));
7e10aea6606a51d35041e5a85f9e4f1bd19c4062vboxsync CHECKL(lrintl(make_lrd_cw(0xad78ebc5ac620000ULL,0xc041,0x0e7f)), (long)(-2147483647L - 1));
7e10aea6606a51d35041e5a85f9e4f1bd19c4062vboxsync CHECK(logl(2.7182818284590452353602874713526625L), 1.0);
9e5c26690d45216629b5f588aced8fcfb68c23b6vboxsync /* Only works in extended precision, while double precision is default on BSD (including Darwin) */
cErrors++;
cErrors++;
return cErrors;
typedef long double CPU86_LDouble;
unsigned long long lower;
unsigned short upper;
typedef long double floatx80;
return rintl(a);
struct myenv
unsigned int fpus;
unsigned int fpuc;
#ifdef USE_X86LDOUBLE
static inline void fpush(void)
static inline void fpop(void)
static void helper_f2xm1(void)
static void helper_fyl2x(void)
fpop();
static void helper_fptan(void)
fpush();
static void helper_fpatan(void)
fpop();
static void helper_fxtract(void)
unsigned int expdif;
fpush();
static void helper_fprem1(void)
int expdif;
static void helper_fprem(void)
LogFlow(("helper_fprem: ST0=%.*Rhxs ST1=%.*Rhxs fpus=%#x\n", sizeof(ST0), &ST0, sizeof(ST1), &ST1, env->fpus));
int expdif;
static void helper_fyl2xp1(void)
fpop();
static void helper_fsqrt(void)
static void helper_fsincos(void)
fpush();
static void helper_frndint(void)
static void helper_fscale(void)
static void helper_fsin(void)
static void helper_fcos(void)
static void helper_fxam_ST0(void)
int expdif;
#ifdef USE_X86LDOUBLE
} else if (expdif == 0) {
void check_env(void)
#if 0 /* insert this into helper.c */
unsigned int my_fpstt;
unsigned int my_fpus;
unsigned int my_fpuc;
void hlp_fpu_enter(void)
Log(("/*code*/ *(unsigned long long *)&env_org.fpregs[%d] = %#018llxULL; ((unsigned short *)&env_org.fpregs[%d])[4] = %#06x; env_org.fptags[%d]=%d;\n",
Log(("/*code*/ *(unsigned long long *)&env_res.fpregs[%d] = %#018llxULL; ((unsigned short *)&env_res.fpregs[%d])[4] = %#06x; env_res.fptags[%d]=%d;\n",
#endif /* helper.c */
extern void testmath2(void )
#ifdef MATHTEST_STANDALONE
void test_fops(double a, double b)
int main()
testmath2();
return cErrors;