aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/mingw/misc/fegetenv.c
blob: c1169cda7c96889e3dec92c158c7fa2f85ccb506 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
 * This file has no copyright assigned and is placed in the Public Domain.
 * This file is part of the mingw-w64 runtime package.
 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
 */

#include <internal.h>

/* 7.6.4.1
   The fegetenv function stores the current floating-point environment
   in the object pointed to by envp.  */

int fegetenv(fenv_t *env)
{
#if defined(__i386__) || (defined(__x86_64__) && !defined(__arm64ec__))
    unsigned int x87, sse;
    __mingw_control87_2(0, 0, &x87, &sse);
    env->_Fe_ctl = fenv_encode(x87, sse);
    __mingw_setfp(NULL, 0, &x87, 0);
    __mingw_setfp_sse(NULL, 0, &sse, 0);
    env->_Fe_stat = fenv_encode(x87, sse);
#else
    env->_Fe_ctl = fenv_encode(0, __mingw_controlfp(0, 0));
    env->_Fe_stat = fenv_encode(0, __mingw_statusfp());
#endif
  return 0;
}