summaryrefslogtreecommitdiff
path: root/libc/src/math/generic/nexttowardl.cpp
diff options
context:
space:
mode:
authorNishant Mittal <mittalnishant14@outlook.com>2023-11-21 19:32:51 +0530
committerGitHub <noreply@github.com>2023-11-21 09:02:51 -0500
commit0c49fc4c68aff96ebe700d2af50a3c445ee0484e (patch)
tree97e28913a4d631138cde639819f0f3407157a431 /libc/src/math/generic/nexttowardl.cpp
parentf79676a17eae4c63318561ba35613d97053fa12c (diff)
[libc][math] Implement nexttoward functions (#72763)
Implements the `nexttoward`, `nexttowardf` and `nexttowardl` functions. Also, raise excepts required by the standard in `nextafter` functions. cc: @lntue
Diffstat (limited to 'libc/src/math/generic/nexttowardl.cpp')
-rw-r--r--libc/src/math/generic/nexttowardl.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/libc/src/math/generic/nexttowardl.cpp b/libc/src/math/generic/nexttowardl.cpp
new file mode 100644
index 000000000000..0c887ae0671b
--- /dev/null
+++ b/libc/src/math/generic/nexttowardl.cpp
@@ -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);
+}
+
+} // namespace LIBC_NAMESPACE