Cygwin: (mostly) drop NT4 and Samba < 3.0 support
[newlib-cygwin.git] / winsup / cygwin / math / modfl.c
blob33593e6def72ddaf60118aac2a2764c73de5bd27
1 /**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6 #include <fenv.h>
7 #include <math.h>
8 #include <errno.h>
10 long double
11 modfl (long double value, long double* iptr)
13 long double int_part = 0.0L;
14 /* truncate */
15 #if defined(_AMD64_) || defined(__x86_64__)
16 asm volatile ("subq $8, %%rsp\n"
17 "fnstcw 4(%%rsp)\n"
18 "movzwl 4(%%rsp), %%eax\n"
19 "orb $12, %%ah\n"
20 "movw %%ax, (%%rsp)\n"
21 "fldcw (%%rsp)\n"
22 "frndint\n"
23 "fldcw 4(%%rsp)\n"
24 "addq $8, %%rsp\n" : "=t" (int_part) : "0" (value) : "eax"); /* round */
25 #elif defined(_X86_) || defined(__i386__)
26 asm volatile ("push %%eax\n\tsubl $8, %%esp\n"
27 "fnstcw 4(%%esp)\n"
28 "movzwl 4(%%esp), %%eax\n"
29 "orb $12, %%ah\n"
30 "movw %%ax, (%%esp)\n"
31 "fldcw (%%esp)\n"
32 "frndint\n"
33 "fldcw 4(%%esp)\n"
34 "addl $8, %%esp\n\tpop %%eax\n" : "=t" (int_part) : "0" (value) : "eax"); /* round */
35 #else
36 int_part = truncl(value);
37 #endif
38 if (iptr)
39 *iptr = int_part;
40 return (isinf (value) ? 0.0L : value - int_part);