master
 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
10long double
11modfl (long double value, long double* iptr)
12{
13  long double int_part = 0.0L;
14  /* truncate */
15#if (defined(_AMD64_) && !defined(_ARM64EC_)) || (defined(__x86_64__) && !defined(__arm64ec__))
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);
41}