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
496496 __asm__ (
497497 "fldl %1\n"
498498 "frndint \n"
499− "fstl %0\n" : "=m" (retval) : "m" (x));
499+ "fstpl %0\n" : "=m" (retval) : "m" (x));
500500 return retval;
501501 }
502502
@@ -506,18 +506,23 @@ extern "C" { · 3 unmodified lines
506506 __asm__ (
507507 "flds %1\n"
508508 "frndint \n"
509− "fsts %0\n" : "=m" (retval) : "m" (x));
509+ "fstps %0\n" : "=m" (retval) : "m" (x));
510510 return retval;
511511 }
512512
513513 __CRT_INLINE long double __cdecl rintl (long double x)
514514 {
515+#ifdef _WIN32
516+ // on win32 'long double' is double internally
517+ return rint(x);
518+#else
515519 long double retval;
516520 __asm__ (
517521 "fldt %1\n"
518522 "frndint \n"
519− "fstt %0\n" : "=m" (retval) : "m" (x));
523+ "fstpt %0\n" : "=m" (retval) : "m" (x));
520524 return retval;
525+#endif
521526 }
522527
523528 /* 7.12.9.5 */
@@ -591,7 +596,7 @@ extern "C" { · 67 unmodified lines
591596 __asm__ ("fldcw %0;" : : "m" (tmp_cw));
592597 __asm__ ("fldl %1;"
593598 "frndint;"
594− "fstl %0;" : "=m" (retval) : "m" (_x)); /* round towards zero */
599+ "fstpl %0;" : "=m" (retval) : "m" (_x)); /* round towards zero */
595600 __asm__ ("fldcw %0;" : : "m" (saved_cw) ); /* restore saved control word */
596601 return retval;
597602 }

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