Skip to content

Commit 8e5704c

Browse files
committed
test: Check invalid value in call to fesetround()
An invalid parameter to fesetround shall not change the rounding mode and will return a non-zero value. Signed-off-by: Keith Packard <[email protected]>
1 parent 608e705 commit 8e5704c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/rounding-mode.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,17 @@ check(int mode, char *name, double value)
150150
printf("ERROR fesetround %s failed\n", name);
151151
ret++;
152152
}
153+
/* Make sure setting an invalid rounding mode fails and doesn't
154+
* change the test results
155+
*/
156+
if (fesetround(FE_ALL_EXCEPT+1) == 0) {
157+
printf("ERROR fesetround %d succeeded\n", FE_ALL_EXCEPT+1);
158+
ret++;
159+
}
160+
if (fegetround() != mode) {
161+
printf("ERROR fegetround() != %s\n", name);
162+
ret++;
163+
}
153164
got = nearbyint(value);
154165
if (want != got) {
155166
printf("ERROR double %s: value %g want %g got %g\n", name, value, want, got);
@@ -176,6 +187,17 @@ check(int mode, char *name, double value)
176187
printf("ERROR fesetround %s failed\n", name);
177188
ret++;
178189
}
190+
/* Make sure setting an invalid rounding mode fails and doesn't
191+
* change the test results
192+
*/
193+
if (fesetround(FE_ALL_EXCEPT+1) == 0) {
194+
printf("ERROR fesetround %d succeeded\n", FE_ALL_EXCEPT+1);
195+
ret++;
196+
}
197+
if (fegetround() != mode) {
198+
printf("ERROR fegetround() != %s\n", name);
199+
ret++;
200+
}
179201
gotf = nearbyintf(valuef);
180202
if (wantf != gotf) {
181203
printf("ERROR float %s: value %g want %g got %g\n", name, (double) valuef, (double) wantf, (double) gotf);

0 commit comments

Comments
 (0)