Module Name:    src
Committed By:   maya
Date:           Mon May 27 00:10:36 UTC 2019

Modified Files:
        src/tests/lib/libm: t_cos.c

Log Message:
on i386 with FLT_EVAL_METHOD=2, the computation inside cosf was done in
binary80 arithmetic and never rounded to binary32 at the end, so it
appeared farther from the correctly rounded result in binary32 than expected.

Force binary32 using volatile float.

PR lib/54232: lib/libm/t_cos:cosf_angles regression on i386

>From Riastradh.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libm/t_cos.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libm/t_cos.c
diff -u src/tests/lib/libm/t_cos.c:1.8 src/tests/lib/libm/t_cos.c:1.9
--- src/tests/lib/libm/t_cos.c:1.8	Thu Apr 25 22:58:23 2019
+++ src/tests/lib/libm/t_cos.c	Mon May 27 00:10:36 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: t_cos.c,v 1.8 2019/04/25 22:58:23 maya Exp $ */
+/* $NetBSD: t_cos.c,v 1.9 2019/05/27 00:10:36 maya Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -275,13 +275,24 @@ ATF_TC_BODY(cosf_angles, tc)
 		float theta = angles[i].x;
 		float cos_theta = angles[i].fy;
 
+		/*
+		 * Force rounding to float even if FLT_EVAL_METHOD=2,
+		 * as is the case on i386.
+		 *
+		 * The volatile should not be necessary, by C99 Sec.
+		 * 5.2.4.2.2. para. 8 on p. 24 which specifies that
+		 * assignment and cast remove all extra range and precision,
+		 * but seems to be needed to work around a compiler bug.
+		 */ 
+		volatile float result = cosf(theta);
+
 		if (cos_theta == 999)
 			cos_theta = angles[i].y;
 
 		assert(cos_theta != 0);
-		if (!(fabsf((cosf(theta) - cos_theta)/cos_theta) <= eps)) {
+		if (!(fabsf((result - cos_theta)/cos_theta) <= eps)) {
 			atf_tc_fail_nonfatal("cosf(%d deg = %.8g) = %.8g"
-			    " != %.8g", deg, theta, cos(theta), cos_theta);
+			    " != %.8g", deg, theta, result, cos_theta);
 		}
 	}
 }

Reply via email to