[libc-commits] [libc] [llvm] [libc] Add fixed point support to printf (PR #82707)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Mon Feb 26 16:07:37 PST 2024


================
@@ -0,0 +1,133 @@
+//===-- printf_fixed_conv_fuzz.cpp ----------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// Fuzzing test for llvm-libc printf %f/e/g/a implementations.
+///
+//===----------------------------------------------------------------------===//
+#include "src/stdio/snprintf.h"
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/fixed_point/fx_rep.h"
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "utils/MPFRWrapper/mpfr_inc.h"
+
+constexpr int MAX_SIZE = 10000;
+
+inline bool simple_streq(char *first, char *second, int length) {
+  for (int i = 0; i < length; ++i)
+    if (first[i] != second[i])
+      return false;
+
+  return true;
+}
+
+inline int clamp(int num, int max) {
+  if (num > max)
+    return max;
+  if (num < -max)
+    return -max;
+  return num;
+}
----------------
nickdesaulniers wrote:

At some point, it might be worthwhile to add something akin to std::clamp to libc/src/__support/CPP/algorithm.h.

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


More information about the libc-commits mailing list