From 38711492082c4d5a5f338b1df90b4588e9d4f3b3 Mon Sep 17 00:00:00 2001 From: Yilong Guo Date: Tue, 14 Oct 2025 23:47:59 +0800 Subject: [PATCH] commonfns: Fix max_error initialization and improve test output (#2500) Before this change, `max_error` was initialized to `0.0f`, which caused issues when the actual maximum `error` was also `0.0f`. In such cases, `max_val` would never be updated, leading to misleading test output showing `NaN` values: ``` degrees: Max error 0.000000 ulps at 0: *nan vs 0x1.9802318e8abefp+21 ``` This fix initializes `max_error` to `-INFINITY` to ensure `max_val` is always updated at least once. Additionally, the log output now includes the input value for better debugging: ``` degrees: Max error 0.000000 ulps at 0, input 0x1.c7bffcp+15: *0x1.9802318e8abefp+21 vs 0x1.9802318e8abefp+21 ``` This makes the test output more informative and eliminates confusing `NaN` values in the summary. --- test_conformance/commonfns/test_unary_fn.cpp | 34 ++++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/test_conformance/commonfns/test_unary_fn.cpp b/test_conformance/commonfns/test_unary_fn.cpp index 6515adf7..599067d2 100644 --- a/test_conformance/commonfns/test_unary_fn.cpp +++ b/test_conformance/commonfns/test_unary_fn.cpp @@ -57,7 +57,7 @@ namespace { template int verify_degrees(const T *const inptr, const T *const outptr, int n) { - float error, max_error = 0.0f; + float error, max_error = -INFINITY; double r, max_val = NAN; int max_index = 0; @@ -89,13 +89,16 @@ int verify_degrees(const T *const inptr, const T *const outptr, int n) } if (std::is_same::value) - log_info("degrees: Max error %f ulps at %d: *%a vs %a (*%g vs %g)\n", - max_error, max_index, max_val, conv_to_flt(outptr[max_index]), - max_val, conv_to_flt(outptr[max_index])); + log_info("degrees: Max error %f ulps at %d, input %a: *%a vs %a (*%g " + "vs %g)\n", + max_error, max_index, conv_to_flt(inptr[max_index]), max_val, + conv_to_flt(outptr[max_index]), max_val, + conv_to_flt(outptr[max_index])); else - log_info("degrees: Max error %f ulps at %d: *%a vs %a (*%g vs %g)\n", - max_error, max_index, max_val, outptr[max_index], max_val, - outptr[max_index]); + log_info("degrees: Max error %f ulps at %d, input %a: *%a vs %a (*%g " + "vs %g)\n", + max_error, max_index, conv_to_flt(inptr[max_index]), max_val, + outptr[max_index], max_val, outptr[max_index]); return 0; } @@ -103,7 +106,7 @@ int verify_degrees(const T *const inptr, const T *const outptr, int n) template int verify_radians(const T *const inptr, const T *const outptr, int n) { - float error, max_error = 0.0f; + float error, max_error = -INFINITY; double r, max_val = NAN; int max_index = 0; @@ -135,13 +138,16 @@ int verify_radians(const T *const inptr, const T *const outptr, int n) } if (std::is_same::value) - log_info("radians: Max error %f ulps at %d: *%a vs %a (*%g vs %g)\n", - max_error, max_index, max_val, conv_to_flt(outptr[max_index]), - max_val, conv_to_flt(outptr[max_index])); + log_info("radians: Max error %f ulps at %d, input %a: *%a vs %a (*%g " + "vs %g)\n", + max_error, max_index, conv_to_flt(inptr[max_index]), max_val, + conv_to_flt(outptr[max_index]), max_val, + conv_to_flt(outptr[max_index])); else - log_info("radians: Max error %f ulps at %d: *%a vs %a (*%g vs %g)\n", - max_error, max_index, max_val, outptr[max_index], max_val, - outptr[max_index]); + log_info("radians: Max error %f ulps at %d, input %a: *%a vs %a (*%g " + "vs %g)\n", + max_error, max_index, conv_to_flt(inptr[max_index]), max_val, + outptr[max_index], max_val, outptr[max_index]); return 0; }