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
10float
11modff (float value, float* iptr)
12{
13 float int_part = 0.0F;
14 /* truncate */
15 /* truncate */
16#if (defined(_AMD64_) && !defined(_ARM64EC_)) || (defined(__x86_64__) && !defined(__arm64ec__))
17 asm volatile ("subq $8, %%rsp\n"
18 "fnstcw 4(%%rsp)\n"
19 "movzwl 4(%%rsp), %%eax\n"
20 "orb $12, %%ah\n"
21 "movw %%ax, (%%rsp)\n"
22 "fldcw (%%rsp)\n"
23 "frndint\n"
24 "fldcw 4(%%rsp)\n"
25 "addq $8, %%rsp\n" : "=t" (int_part) : "0" (value) : "eax"); /* round */
26#elif defined(_X86_) || defined(__i386__)
27 asm volatile ("push %%eax\n\tsubl $8, %%esp\n"
28 "fnstcw 4(%%esp)\n"
29 "movzwl 4(%%esp), %%eax\n"
30 "orb $12, %%ah\n"
31 "movw %%ax, (%%esp)\n"
32 "fldcw (%%esp)\n"
33 "frndint\n"
34 "fldcw 4(%%esp)\n"
35 "addl $8, %%esp\n\tpop %%eax\n" : "=t" (int_part) : "0" (value) : "eax"); /* round */
36#else
37 int_part = truncf(value);
38#endif
39 if (iptr)
40 *iptr = int_part;
41 return (isinf (value) ? 0.0F : value - int_part);
42}