Debian Codegraph @

share/libc/fenv.c

raw
1 /**************************************************************************/
2 /* */
3 /* This file is part of Frama-C. */
4 /* */
5 /* Copyright (C) 2007-2022 */
6 /* CEA (Commissariat à l'énergie atomique et aux énergies */
7 /* alternatives) */
8 /* */
9 /* you can redistribute it and/or modify it under the terms of the GNU */
10 /* Lesser General Public License as published by the Free Software */
11 /* Foundation, version 2.1. */
12 /* */
13 /* It is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
16 /* GNU Lesser General Public License for more details. */
17 /* */
18 /* See the GNU Lesser General Public License version 2.1 */
19 /* for more details (enclosed in the file licenses/LGPLv2.1). */
20 /* */
21 /**************************************************************************/
22
23 /* ISO C: 7.6 */
24 #include "fenv.h"
25 __PUSH_FC_STDLIB
26
27 /** Determines which of a specified subset of the floating-point exception flags
28 * are currently set.
29 * \param excepts Specifies the floating-point status flags to be queried.
30 * \return The value of the bitwise OR of the floating-point exception macros
31 * corresponding to the currently set floating-point exceptions included in
32 * parameter excepts.
33 */
34 int fetestexcept( int excepts )
35 {
36 static volatile int __fc_random_fetestexcept; /* random represent the FPU status word. */
37
38 return (0x00FF & __fc_random_fetestexcept); /* B, C3, TOSP, C2, C1, and C0 don't matter. Mask the selected bits. */
39 }
40
41
42 volatile fenv_t __fc_fenv_state;
43
44
45 /** Saves the current floating-point environment in the object pointed to by
46 * envp, clears the floating-point status flags, and then installs a non-stop
47 * (continue on floating-point exceptions) mode for all floating-point
48 * exceptions.
49 * \return Always returns zero.
50 */
51 int feholdexcept( fenv_t *envp )
52 {
53 *envp = __fc_fenv_state; /* store the current FPU environment */
54
55 return 0;
56 }
57
58
59 /** Establishes the floating-point environment represented by the object pointed
60 * to by envp. The argument envp shall point to a valid floating-point
61 * environment object.
62 * In principle, this function has the potential to trigger pending previous
63 * exceptions: If envp contains a raised exception flag and at the same time
64 * unmasks that exception type, then this will cause an interrupt.
65 */
66 int fesetenv( const fenv_t *envp )
67 {
68 __fc_fenv_state = *envp;
69 return 0;
70 }
71
72 __POP_FC_STDLIB