Skip to content

Commit

Permalink
test: Check invalid value in call to fesetround()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
keith-packard committed Apr 17, 2024
1 parent 608e705 commit 8e5704c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/rounding-mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ check(int mode, char *name, double value)
printf("ERROR fesetround %s failed\n", name);
ret++;
}
/* Make sure setting an invalid rounding mode fails and doesn't
* change the test results
*/
if (fesetround(FE_ALL_EXCEPT+1) == 0) {
printf("ERROR fesetround %d succeeded\n", FE_ALL_EXCEPT+1);
ret++;
}
if (fegetround() != mode) {
printf("ERROR fegetround() != %s\n", name);
ret++;
}
got = nearbyint(value);
if (want != got) {
printf("ERROR double %s: value %g want %g got %g\n", name, value, want, got);
Expand All @@ -176,6 +187,17 @@ check(int mode, char *name, double value)
printf("ERROR fesetround %s failed\n", name);
ret++;
}
/* Make sure setting an invalid rounding mode fails and doesn't
* change the test results
*/
if (fesetround(FE_ALL_EXCEPT+1) == 0) {
printf("ERROR fesetround %d succeeded\n", FE_ALL_EXCEPT+1);
ret++;
}
if (fegetround() != mode) {
printf("ERROR fegetround() != %s\n", name);
ret++;
}
gotf = nearbyintf(valuef);
if (wantf != gotf) {
printf("ERROR float %s: value %g want %g got %g\n", name, (double) valuef, (double) wantf, (double) gotf);
Expand Down

0 comments on commit 8e5704c

Please sign in to comment.