1 /* Determine floating-point rounding mode within libc. Generic version.
2 Copyright (C) 2012-2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #ifndef _GET_ROUNDING_MODE_H
20 #define _GET_ROUNDING_MODE_H 1
22 #include <fpu_control.h>
25 /* Define values for FE_* modes not defined for this architecture. */
27 # define ORIG_FE_DOWNWARD FE_DOWNWARD
29 # define ORIG_FE_DOWNWARD 0
32 # define ORIG_FE_TONEAREST FE_TONEAREST
34 # define ORIG_FE_TONEAREST 0
37 # define ORIG_FE_TOWARDZERO FE_TOWARDZERO
39 # define ORIG_FE_TOWARDZERO 0
42 # define ORIG_FE_UPWARD FE_UPWARD
44 # define ORIG_FE_UPWARD 0
46 #define FE_CONSTRUCT_DISTINCT_VALUE(X, Y, Z) \
47 ((((X) & 1) | ((Y) & 2) | ((Z) & 4)) ^ 7)
49 # define FE_DOWNWARD FE_CONSTRUCT_DISTINCT_VALUE (ORIG_FE_TONEAREST, \
54 # define FE_TONEAREST FE_CONSTRUCT_DISTINCT_VALUE (FE_DOWNWARD, \
59 # define FE_TOWARDZERO FE_CONSTRUCT_DISTINCT_VALUE (FE_DOWNWARD, \
64 # define FE_UPWARD FE_CONSTRUCT_DISTINCT_VALUE (FE_DOWNWARD, \
69 /* Return the floating-point rounding mode. */
72 get_rounding_mode (void)
74 #if (defined _FPU_RC_DOWN \
75 || defined _FPU_RC_NEAREST \
76 || defined _FPU_RC_ZERO \
77 || defined _FPU_RC_UP)
79 const fpu_control_t mask
= (0
83 # ifdef _FPU_RC_NEAREST
102 # ifdef _FPU_RC_NEAREST
103 case _FPU_RC_NEAREST
:
109 return FE_TOWARDZERO
;
125 #endif /* get-rounding-mode.h */