win32/include/math.h: rint/trunc: pop fp stack

... in order to avoid fp stack overflow (see test below).

#include <math.h>
#include <stdio.h>
int main()
{
   printf("%f %f %f %f\n", trunc(1.2), rint(1.2), trunc(1.2), rint(1.2));
   printf("%f %f %f %f\n", trunc(1.2), rint(1.2), trunc(1.2), rint(1.2));
   printf("%f %f %f %f\n", trunc(1.2), rint(1.2), trunc(1.2), rintl(1.2));
}

Also in rintl:
- 'long double' is not a ten-byte float on windows.
mob
grischka 2020-02-24 15:48:01 +01:00
parent 024214af2d
commit d019586378
1 changed files with 9 additions and 4 deletions

View File

@ -496,7 +496,7 @@ extern "C" {
__asm__ (
"fldl %1\n"
"frndint \n"
"fstl %0\n" : "=m" (retval) : "m" (x));
"fstpl %0\n" : "=m" (retval) : "m" (x));
return retval;
}
@ -506,18 +506,23 @@ extern "C" {
__asm__ (
"flds %1\n"
"frndint \n"
"fsts %0\n" : "=m" (retval) : "m" (x));
"fstps %0\n" : "=m" (retval) : "m" (x));
return retval;
}
__CRT_INLINE long double __cdecl rintl (long double x)
{
#ifdef _WIN32
// on win32 'long double' is double internally
return rint(x);
#else
long double retval;
__asm__ (
"fldt %1\n"
"frndint \n"
"fstt %0\n" : "=m" (retval) : "m" (x));
"fstpt %0\n" : "=m" (retval) : "m" (x));
return retval;
#endif
}
/* 7.12.9.5 */
@ -591,7 +596,7 @@ extern "C" {
__asm__ ("fldcw %0;" : : "m" (tmp_cw));
__asm__ ("fldl %1;"
"frndint;"
"fstl %0;" : "=m" (retval) : "m" (_x)); /* round towards zero */
"fstpl %0;" : "=m" (retval) : "m" (_x)); /* round towards zero */
__asm__ ("fldcw %0;" : : "m" (saved_cw) ); /* restore saved control word */
return retval;
}