1 /* Determine floating-point rounding mode within libc. Generic version.
2 Copyright (C) 2012-2014 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>
24 /* Define values for FE_* modes not defined for this architecture. */
26 # define ORIG_FE_DOWNWARD FE_DOWNWARD
28 # define ORIG_FE_DOWNWARD 0
31 # define ORIG_FE_TONEAREST FE_TONEAREST
33 # define ORIG_FE_TONEAREST 0
36 # define ORIG_FE_TOWARDZERO FE_TOWARDZERO
38 # define ORIG_FE_TOWARDZERO 0
41 # define ORIG_FE_UPWARD FE_UPWARD
43 # define ORIG_FE_UPWARD 0
45 #define FE_CONSTRUCT_DISTINCT_VALUE(X, Y, Z) \
46 ((((X) & 1) | ((Y) & 2) | ((Z) & 4)) ^ 7)
48 # define FE_DOWNWARD FE_CONSTRUCT_DISTINCT_VALUE (ORIG_FE_TONEAREST, \
53 # define FE_TONEAREST FE_CONSTRUCT_DISTINCT_VALUE (FE_DOWNWARD, \
58 # define FE_TOWARDZERO FE_CONSTRUCT_DISTINCT_VALUE (FE_DOWNWARD, \
63 # define FE_UPWARD FE_CONSTRUCT_DISTINCT_VALUE (FE_DOWNWARD, \
68 /* Return the floating-point rounding mode. */
71 get_rounding_mode (void)
73 #if (defined _FPU_RC_DOWN \
74 || defined _FPU_RC_NEAREST \
75 || defined _FPU_RC_ZERO \
76 || defined _FPU_RC_UP)
78 const fpu_control_t mask
= (0
82 # ifdef _FPU_RC_NEAREST
101 # ifdef _FPU_RC_NEAREST
102 case _FPU_RC_NEAREST
:
108 return FE_TOWARDZERO
;
124 #endif /* get-rounding-mode.h */