Branch
Hash :
a0d10f43
Author :
Date :
2025-10-20T20:50:21
fenv-rounding tests: Avoid test failure on Android. * tests/test-fenv-round.c (test_towardzero, test_upward) (test_downward): Disable tests that are known to fail. * doc/posix-functions/fesetround.texi: Update list of platforms.
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
/* Test of floating-point rounding direction.
Copyright (C) 2023-2025 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
/* Written by Bruno Haible <bruno@clisp.org>, 2023. */
#include <config.h>
/* Specification. */
#include <fenv.h>
#include "macros.h"
/* Check the FE_TOWARDZERO rounding direction. */
_GL_UNUSED static void
test_towardzero ()
{
{
float volatile a, b, q, p;
a = 1; b = 3; q = a / b; p = b * q;
ASSERT (p < a);
a = -1; b = 3; q = a / b; p = b * q;
ASSERT (p > a);
}
{
double volatile a, b, q, p;
a = 1; b = 3; q = a / b; p = b * q;
ASSERT (p < a);
a = -1; b = 3; q = a / b; p = b * q;
ASSERT (p > a);
}
#if !(((defined __FreeBSD__ || defined __OpenBSD__ || defined __ANDROID__) && defined __aarch64__) || (defined __NetBSD__ && defined __sparcv9 /* sparc64 */) || (defined __OpenBSD__ && defined __mips64))
{
long double volatile a, b, q, p;
a = 1; b = 3; q = a / b; p = b * q;
ASSERT (p < a);
a = -1; b = 3; q = a / b; p = b * q;
ASSERT (p > a);
}
#endif
}
/* Check the FE_UPWARD rounding direction. */
_GL_UNUSED static void
test_upward ()
{
{
float volatile a, b, q, p;
a = 1; b = 3; q = a / b; p = b * q;
ASSERT (p > a);
a = -1; b = 3; q = a / b; p = b * q;
ASSERT (p > a);
}
{
double volatile a, b, q, p;
a = 1; b = 3; q = a / b; p = b * q;
ASSERT (p > a);
a = -1; b = 3; q = a / b; p = b * q;
ASSERT (p > a);
}
#if !(((defined __FreeBSD__ || defined __OpenBSD__ || defined __ANDROID__) && defined __aarch64__) || (defined __NetBSD__ && defined __sparcv9 /* sparc64 */) || (defined __OpenBSD__ && defined __mips64))
{
long double volatile a, b, q, p;
a = 1; b = 3; q = a / b; p = b * q;
ASSERT (p > a);
a = -1; b = 3; q = a / b; p = b * q;
ASSERT (p > a);
}
#endif
}
/* Check the FE_DOWNWARD rounding direction. */
_GL_UNUSED static void
test_downward ()
{
{
float volatile a, b, q, p;
a = 1; b = 3; q = a / b; p = b * q;
ASSERT (p < a);
a = -1; b = 3; q = a / b; p = b * q;
ASSERT (p < a);
}
{
double volatile a, b, q, p;
a = 1; b = 3; q = a / b; p = b * q;
ASSERT (p < a);
a = -1; b = 3; q = a / b; p = b * q;
ASSERT (p < a);
}
#if !(((defined __FreeBSD__ || defined __OpenBSD__ || defined __ANDROID__) && defined __aarch64__) || (defined __NetBSD__ && defined __sparcv9 /* sparc64 */) || (defined __OpenBSD__ && defined __mips64))
{
long double volatile a, b, q, p;
a = 1; b = 3; q = a / b; p = b * q;
ASSERT (p < a);
a = -1; b = 3; q = a / b; p = b * q;
ASSERT (p < a);
}
#endif
}
/* Check the FE_TONEAREST rounding direction. */
static void
test_tonearest ()
{
{
float volatile a, b, q, p;
a = 1; b = 3; q = a / b; p = b * q;
ASSERT (p == a);
a = -1; b = 3; q = a / b; p = b * q;
ASSERT (p == a);
}
{
double volatile a, b, q, p;
a = 1; b = 3; q = a / b; p = b * q;
ASSERT (p == a);
a = -1; b = 3; q = a / b; p = b * q;
ASSERT (p == a);
}
{
long double volatile a, b, q, p;
a = 1; b = 3; q = a / b; p = b * q;
ASSERT (p == a);
a = -1; b = 3; q = a / b; p = b * q;
ASSERT (p == a);
}
}
int
main ()
{
/* Check that the default rounding direction is FE_TONEAREST. */
test_tonearest ();
/* On alpha, this test works only when compiled with the GCC option
'-mfp-rounding-mode=d'. */
#if !((defined __arm__ && defined __SOFTFP__) || defined __alpha)
# if defined FE_TOWARDZERO
ASSERT (fesetround (FE_TOWARDZERO) == 0);
test_towardzero ();
ASSERT (fegetround () == FE_TOWARDZERO);
# endif
# if defined FE_UPWARD
ASSERT (fesetround (FE_UPWARD) == 0);
test_upward ();
ASSERT (fegetround () == FE_UPWARD);
# endif
# if defined FE_DOWNWARD
ASSERT (fesetround (FE_DOWNWARD) == 0);
test_downward ();
ASSERT (fegetround () == FE_DOWNWARD);
# endif
#endif
ASSERT (fesetround (FE_TONEAREST) == 0);
test_tonearest ();
ASSERT (fegetround () == FE_TONEAREST);
return test_exit_status;
}