• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>
9 
10 double
modf(double value,double * iptr)11 modf (double value, double* iptr)
12 {
13   double int_part = 0.0;
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 = trunc(value);
37 #endif
38   if (iptr)
39     *iptr = int_part;
40   return (isinf (value) ?  0.0 : value - int_part);
41 }
42