https://git.reactos.org/?p=reactos.git;a=commitdiff;h=bc9409daba5ad76765434…
commit bc9409daba5ad76765434de639c6c66d583b3dce
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Fri Jul 15 18:51:20 2022 +0200
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Sun Jul 17 17:32:32 2022 +0200
[CRT] Add round and roundf and add it to msvcrtex to make clang v14 happy
---
sdk/include/crt/math.h | 3 +++
sdk/lib/crt/math/round.c | 16 ++++++++++++++++
sdk/lib/crt/math/roundf.c | 16 ++++++++++++++++
sdk/lib/crt/msvcrtex.cmake | 2 ++
4 files changed, 37 insertions(+)
diff --git a/sdk/include/crt/math.h b/sdk/include/crt/math.h
index ce896484cd7..80aafd21d9c 100644
--- a/sdk/include/crt/math.h
+++ b/sdk/include/crt/math.h
@@ -275,6 +275,8 @@ _Check_return_ long lrintf(_In_ float x);
_Check_return_ long lrintl(_In_ long double x);
#pragma function(lrint, lrintf, lrintl)
#endif
+
+#ifndef _CRTBLD
_Check_return_ __CRT_INLINE double round(_In_ double x) { return (x < 0) ? ceil(x -
0.5f) : floor(x + 0.5); }
_Check_return_ __CRT_INLINE float roundf(_In_ float x) { return (x < 0) ? ceilf(x -
0.5f) : floorf(x + 0.5); }
_Check_return_ __CRT_INLINE long double roundl(_In_ long double x) { return (x < 0) ?
ceill(x - 0.5f) : floorl(x + 0.5); }
@@ -294,6 +296,7 @@ _Check_return_ __CRT_INLINE long long llrint(_In_ double x) { return
(long long)
_Check_return_ __CRT_INLINE long long llrintf(_In_ float x) { return (long long)((x <
0) ? (x - 0.5f) : (x + 0.5)); }
_Check_return_ __CRT_INLINE long long llrintl(_In_ long double x) { return (long long)((x
< 0) ? (x - 0.5f) : (x + 0.5)); }
_Check_return_ __CRT_INLINE double log2(_In_ double x) { return log(x) / log(2); }
+#endif /* !_CRTBLD */
#ifndef NO_OLDNAMES /* !__STDC__ */
diff --git a/sdk/lib/crt/math/round.c b/sdk/lib/crt/math/round.c
new file mode 100644
index 00000000000..36eec2dd776
--- /dev/null
+++ b/sdk/lib/crt/math/round.c
@@ -0,0 +1,16 @@
+/*
+ * COPYRIGHT: BSD - See COPYING.ARM in the top level directory
+ * PROJECT: ReactOS CRT library
+ * PURPOSE: Portable implementation of round
+ * PROGRAMMER: Timo Kreuzer (timo.kreuzer(a)reactos.org)
+ */
+
+#include <math.h>
+
+double round(double arg)
+{
+ if (arg < 0.0)
+ return ceil(arg - 0.5);
+ else
+ return floor(arg + 0.5);
+}
diff --git a/sdk/lib/crt/math/roundf.c b/sdk/lib/crt/math/roundf.c
new file mode 100644
index 00000000000..454484a649e
--- /dev/null
+++ b/sdk/lib/crt/math/roundf.c
@@ -0,0 +1,16 @@
+/*
+ * COPYRIGHT: BSD - See COPYING.ARM in the top level directory
+ * PROJECT: ReactOS CRT library
+ * PURPOSE: Portable implementation of roundf
+ * PROGRAMMER: Timo Kreuzer (timo.kreuzer(a)reactos.org)
+ */
+
+#include <math.h>
+
+float roundf(float arg)
+{
+ if (arg < 0.0)
+ return ceilf(arg - 0.5);
+ else
+ return floorf(arg + 0.5);
+}
diff --git a/sdk/lib/crt/msvcrtex.cmake b/sdk/lib/crt/msvcrtex.cmake
index e8acbd7e2ca..272d844252e 100644
--- a/sdk/lib/crt/msvcrtex.cmake
+++ b/sdk/lib/crt/msvcrtex.cmake
@@ -13,6 +13,8 @@ list(APPEND MSVCRTEX_SOURCE
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
# Clang performs some optimizations requiring those funtions
list(APPEND MSVCRTEX_SOURCE
+ math/round.c
+ math/roundf.c
math/exp2.c
math/exp2f.c
)