1 /* Test of floating-point rounding direction.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2023. */
26 /* Check the FE_TOWARDZERO rounding direction. */
27 _GL_UNUSED
static void
31 float volatile a
, b
, q
, p
;
33 a
= 1; b
= 3; q
= a
/ b
; p
= b
* q
;
36 a
= -1; b
= 3; q
= a
/ b
; p
= b
* q
;
40 double volatile a
, b
, q
, p
;
42 a
= 1; b
= 3; q
= a
/ b
; p
= b
* q
;
45 a
= -1; b
= 3; q
= a
/ b
; p
= b
* q
;
48 #if !(((defined __FreeBSD__ || defined __OpenBSD__) && defined __aarch64__) || (defined __NetBSD__ && defined __sparcv9 /* sparc64 */) || (defined __OpenBSD__ && defined __mips64))
50 long double volatile a
, b
, q
, p
;
52 a
= 1; b
= 3; q
= a
/ b
; p
= b
* q
;
55 a
= -1; b
= 3; q
= a
/ b
; p
= b
* q
;
61 /* Check the FE_UPWARD rounding direction. */
62 _GL_UNUSED
static void
66 float volatile a
, b
, q
, p
;
68 a
= 1; b
= 3; q
= a
/ b
; p
= b
* q
;
71 a
= -1; b
= 3; q
= a
/ b
; p
= b
* q
;
75 double volatile a
, b
, q
, p
;
77 a
= 1; b
= 3; q
= a
/ b
; p
= b
* q
;
80 a
= -1; b
= 3; q
= a
/ b
; p
= b
* q
;
83 #if !(((defined __FreeBSD__ || defined __OpenBSD__) && defined __aarch64__) || (defined __NetBSD__ && defined __sparcv9 /* sparc64 */) || (defined __OpenBSD__ && defined __mips64))
85 long double volatile a
, b
, q
, p
;
87 a
= 1; b
= 3; q
= a
/ b
; p
= b
* q
;
90 a
= -1; b
= 3; q
= a
/ b
; p
= b
* q
;
96 /* Check the FE_DOWNWARD rounding direction. */
97 _GL_UNUSED
static void
101 float volatile a
, b
, q
, p
;
103 a
= 1; b
= 3; q
= a
/ b
; p
= b
* q
;
106 a
= -1; b
= 3; q
= a
/ b
; p
= b
* q
;
110 double volatile a
, b
, q
, p
;
112 a
= 1; b
= 3; q
= a
/ b
; p
= b
* q
;
115 a
= -1; b
= 3; q
= a
/ b
; p
= b
* q
;
118 #if !(((defined __FreeBSD__ || defined __OpenBSD__) && defined __aarch64__) || (defined __NetBSD__ && defined __sparcv9 /* sparc64 */) || (defined __OpenBSD__ && defined __mips64))
120 long double volatile a
, b
, q
, p
;
122 a
= 1; b
= 3; q
= a
/ b
; p
= b
* q
;
125 a
= -1; b
= 3; q
= a
/ b
; p
= b
* q
;
131 /* Check the FE_TONEAREST rounding direction. */
136 float volatile a
, b
, q
, p
;
138 a
= 1; b
= 3; q
= a
/ b
; p
= b
* q
;
141 a
= -1; b
= 3; q
= a
/ b
; p
= b
* q
;
145 double volatile a
, b
, q
, p
;
147 a
= 1; b
= 3; q
= a
/ b
; p
= b
* q
;
150 a
= -1; b
= 3; q
= a
/ b
; p
= b
* q
;
154 long double volatile a
, b
, q
, p
;
156 a
= 1; b
= 3; q
= a
/ b
; p
= b
* q
;
159 a
= -1; b
= 3; q
= a
/ b
; p
= b
* q
;
167 /* Check that the default rounding direction is FE_TONEAREST. */
170 /* On alpha, this test works only when compiled with the GCC option
171 '-mfp-rounding-mode=d'. */
172 #if !((defined __arm__ && defined __SOFTFP__) || defined __alpha)
173 # if defined FE_TOWARDZERO
174 ASSERT (fesetround (FE_TOWARDZERO
) == 0);
176 ASSERT (fegetround () == FE_TOWARDZERO
);
179 # if defined FE_UPWARD
180 ASSERT (fesetround (FE_UPWARD
) == 0);
182 ASSERT (fegetround () == FE_UPWARD
);
185 # if defined FE_DOWNWARD
186 ASSERT (fesetround (FE_DOWNWARD
) == 0);
188 ASSERT (fegetround () == FE_DOWNWARD
);
192 ASSERT (fesetround (FE_TONEAREST
) == 0);
194 ASSERT (fegetround () == FE_TONEAREST
);
196 return test_exit_status
;