2023-05-16 09:41:46 -07:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2022-05-20 18:59:53 -04:00
|
|
|
From: PJ Reiniger <pj.reiniger@gmail.com>
|
|
|
|
|
Date: Tue, 3 May 2022 22:50:24 -0400
|
2026-05-26 21:55:50 -07:00
|
|
|
Subject: [PATCH 13/34] MathExtras: add Lerp() and sgn()
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
---
|
2024-12-24 17:40:31 -08:00
|
|
|
llvm/include/llvm/Support/MathExtras.h | 21 +++++++++++++++++++++
|
|
|
|
|
1 file changed, 21 insertions(+)
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
|
2026-05-26 16:25:29 -07:00
|
|
|
index b8e858f9c530e31430f824cc2d93ff1cc78a92f7..0735d9c9f756349a19c5aa2ec34ceca5d8274f16 100644
|
2022-05-20 18:59:53 -04:00
|
|
|
--- a/llvm/include/llvm/Support/MathExtras.h
|
|
|
|
|
+++ b/llvm/include/llvm/Support/MathExtras.h
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -764,6 +764,27 @@ using stack_float_t = volatile float;
|
2024-12-24 17:40:31 -08:00
|
|
|
using stack_float_t = float;
|
|
|
|
|
#endif
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
+// Typesafe implementation of the signum function.
|
|
|
|
|
+// Returns -1 if negative, 1 if positive, 0 if 0.
|
|
|
|
|
+template <typename T>
|
|
|
|
|
+constexpr int sgn(T val) {
|
|
|
|
|
+ return (T(0) < val) - (val < T(0));
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * Linearly interpolates between two values.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param startValue The start value.
|
|
|
|
|
+ * @param endValue The end value.
|
|
|
|
|
+ * @param t The fraction for interpolation.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return The interpolated value.
|
|
|
|
|
+ */
|
|
|
|
|
+template <typename T>
|
|
|
|
|
+constexpr T Lerp(const T& startValue, const T& endValue, double t) {
|
|
|
|
|
+ return startValue + (endValue - startValue) * t;
|
|
|
|
|
+}
|
2024-12-24 17:40:31 -08:00
|
|
|
+
|
|
|
|
|
} // namespace llvm
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
#endif
|