From 8e5704ce4a48c1efb26a1faba45ba223a0e651e8 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 16 Apr 2024 14:06:37 -0700 Subject: [PATCH] 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 --- test/rounding-mode.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/rounding-mode.c b/test/rounding-mode.c index 4da9406499..7245c116c4 100644 --- a/test/rounding-mode.c +++ b/test/rounding-mode.c @@ -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); @@ -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);