History

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.

grischka committed 6 years ago

Commit d0195861 parent 024214a1 file · +9 −4Browse files

Unified · Split

win32/include/math.h+9−4
@@ -496,7 +496,7 @@ extern "C" { · 495 unmodified lines
496 __asm__ (496 __asm__ (
497 "fldl %1\n"497 "fldl %1\n"
498 "frndint \n"498 "frndint \n"
499 "fstl %0\n" : "=m" (retval) : "m" (x));499 "fstpl %0\n" : "=m" (retval) : "m" (x));
500 return retval;500 return retval;
501 }501 }
502 502
@@ -506,18 +506,23 @@ extern "C" { · 3 unmodified lines
506 __asm__ (506 __asm__ (
507 "flds %1\n"507 "flds %1\n"
508 "frndint \n"508 "frndint \n"
509 "fsts %0\n" : "=m" (retval) : "m" (x));509 "fstps %0\n" : "=m" (retval) : "m" (x));
510 return retval;510 return retval;
511 }511 }
512 512
513 __CRT_INLINE long double __cdecl rintl (long double x)513 __CRT_INLINE long double __cdecl rintl (long double x)
514 {514 {
515#ifdef _WIN32
516 // on win32 'long double' is double internally
517 return rint(x);
518#else
515 long double retval;519 long double retval;
516 __asm__ (520 __asm__ (
517 "fldt %1\n"521 "fldt %1\n"
518 "frndint \n"522 "frndint \n"
519 "fstt %0\n" : "=m" (retval) : "m" (x));523 "fstpt %0\n" : "=m" (retval) : "m" (x));
520 return retval;524 return retval;
525#endif
521 }526 }
522 527
523 /* 7.12.9.5 */528 /* 7.12.9.5 */
@@ -591,7 +596,7 @@ extern "C" { · 67 unmodified lines
591 __asm__ ("fldcw %0;" : : "m" (tmp_cw));596 __asm__ ("fldcw %0;" : : "m" (tmp_cw));
592 __asm__ ("fldl %1;"597 __asm__ ("fldl %1;"
593 "frndint;"598 "frndint;"
594 "fstl %0;" : "=m" (retval) : "m" (_x)); /* round towards zero */599 "fstpl %0;" : "=m" (retval) : "m" (_x)); /* round towards zero */
595 __asm__ ("fldcw %0;" : : "m" (saved_cw) ); /* restore saved control word */600 __asm__ ("fldcw %0;" : : "m" (saved_cw) ); /* restore saved control word */
596 return retval;601 return retval;
597 }602 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t