[libc-commits] [libc] [libc][math][c23] Add f16sqrtf C23 math function (PR #95251)

via libc-commits libc-commits at lists.llvm.org
Wed Jun 12 06:58:51 PDT 2024


================
@@ -790,6 +792,37 @@ template void explain_unary_operation_single_output_error<float16>(
     Operation op, float16, float16, double, RoundingMode);
 #endif
 
+template <typename OutType, typename InType>
+void explain_unary_narrower_operation_single_output_error(
+    Operation op, InType input, OutType matchValue, double ulp_tolerance,
+    RoundingMode rounding) {
+  unsigned int precision = get_precision<InType>(ulp_tolerance);
+  MPFRNumber mpfrInput(input, precision);
+  MPFRNumber mpfr_result;
+  mpfr_result = unary_operation(op, input, precision, rounding);
+  MPFRNumber mpfrMatchValue(matchValue);
+  cpp::array<char, 4096> msg_data;
+  cpp::StringStream msg(msg_data);
+  msg << "Match value not within tolerance value of MPFR result:\n"
+      << "  Input decimal: " << mpfrInput.str() << '\n';
+  msg << "     Input bits: " << str(FPBits<InType>(input)) << '\n';
+  msg << '\n' << "  Match decimal: " << mpfrMatchValue.str() << '\n';
+  msg << "     Match bits: " << str(FPBits<OutType>(matchValue)) << '\n';
+  msg << '\n' << "    MPFR result: " << mpfr_result.str() << '\n';
+  msg << "   MPFR rounded: " << str(FPBits<OutType>(mpfr_result.as<OutType>()))
+      << '\n';
+  msg << '\n';
+  msg << "      ULP error: " << mpfr_result.ulp_as_mpfr_number(matchValue).str()
+      << '\n';
+  tlog << msg.str();
----------------
overmighty wrote:

Not sure if I should just undo this for now or fix the `msg_data` part. I think it is a pretty nice quality-of-life improvement as it means no longer having to disable multi-threading in exhaustive_test.h to get readable `explain_*_error` output, although there is still some overlap in test logs even with this (I haven't looked into it yet).

https://github.com/llvm/llvm-project/pull/95251


More information about the libc-commits mailing list