[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 08:34:38 PDT 2024
================
@@ -757,26 +757,32 @@ ternary_operation_one_output(Operation op, InputType x, InputType y,
// to build the complete error messages before sending it to the outstream `OS`
// once at the end. This will stop the error messages from interleaving when
// the tests are running concurrently.
-template <typename T>
-void explain_unary_operation_single_output_error(Operation op, T input,
- T matchValue,
+template <typename InputType, typename OutputType>
+void explain_unary_operation_single_output_error(Operation op, InputType input,
+ OutputType matchValue,
double ulp_tolerance,
RoundingMode rounding) {
- unsigned int precision = get_precision<T>(ulp_tolerance);
+ unsigned int precision = get_precision<InputType>(ulp_tolerance);
MPFRNumber mpfrInput(input, precision);
MPFRNumber mpfr_result;
mpfr_result = unary_operation(op, input, precision, rounding);
MPFRNumber mpfrMatchValue(matchValue);
- tlog << "Match value not within tolerance value of MPFR result:\n"
- << " Input decimal: " << mpfrInput.str() << '\n';
- tlog << " Input bits: " << str(FPBits<T>(input)) << '\n';
- tlog << '\n' << " Match decimal: " << mpfrMatchValue.str() << '\n';
- tlog << " Match bits: " << str(FPBits<T>(matchValue)) << '\n';
- tlog << '\n' << " MPFR result: " << mpfr_result.str() << '\n';
- tlog << " MPFR rounded: " << str(FPBits<T>(mpfr_result.as<T>())) << '\n';
- tlog << '\n';
- tlog << " ULP error: "
- << mpfr_result.ulp_as_mpfr_number(matchValue).str() << '\n';
+ cpp::array<char, 1024> msg_buf;
+ cpp::StringStream msg(msg_buf);
+ msg << "Match value not within tolerance value of MPFR result:\n"
+ << " Input decimal: " << mpfrInput.str() << '\n';
+ msg << " Input bits: " << str(FPBits<InputType>(input)) << '\n';
+ msg << '\n' << " Match decimal: " << mpfrMatchValue.str() << '\n';
+ msg << " Match bits: " << str(FPBits<OutputType>(matchValue)) << '\n';
+ msg << '\n' << " MPFR result: " << mpfr_result.str() << '\n';
+ msg << " MPFR rounded: "
+ << str(FPBits<OutputType>(mpfr_result.as<OutputType>())) << '\n';
+ msg << '\n';
+ msg << " ULP error: " << mpfr_result.ulp_as_mpfr_number(matchValue).str()
+ << '\n';
+ if (msg.overflow())
+ __builtin_unreachable();
----------------
overmighty wrote:
The buffer size of 1024 should always be much more than enough.
https://github.com/llvm/llvm-project/pull/95251
More information about the libc-commits
mailing list