[libc-commits] [libc] [libc][math] Implement nexttoward functions (PR #72763)

Nishant Mittal via libc-commits libc-commits at lists.llvm.org
Sat Nov 18 14:05:04 PST 2023


================
@@ -0,0 +1,22 @@
+//===-- Implementation of nexttowardl function ----------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/nexttowardl.h"
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(long double, nexttowardl, (long double x, long double y)) {
+  // We can reuse the nextafter implementation because nexttoward behaves
+  // exactly same as nextafter in case of long doubles. Also, we have explcitly
+  // handled the special 80-bit long doubles in nextafter implementation.
+  return fputil::nextafter(x, y);
----------------
nishantwrp wrote:

Is this the correct place to reuse the `nextafter` implementation? Or should I create a new function in FpUtils for `nexttoward` and call this function there. 

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


More information about the libc-commits mailing list