[CRT] Add round and roundf and add it to msvcrtex to make clang v14 happy

This commit is contained in:
Timo Kreuzer 2022-07-15 18:51:20 +02:00
parent 83faa2da5e
commit bc9409daba
4 changed files with 37 additions and 0 deletions

View file

@ -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__ */

16
sdk/lib/crt/math/round.c Normal file
View file

@ -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@reactos.org)
*/
#include <math.h>
double round(double arg)
{
if (arg < 0.0)
return ceil(arg - 0.5);
else
return floor(arg + 0.5);
}

16
sdk/lib/crt/math/roundf.c Normal file
View file

@ -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@reactos.org)
*/
#include <math.h>
float roundf(float arg)
{
if (arg < 0.0)
return ceilf(arg - 0.5);
else
return floorf(arg + 0.5);
}

View file

@ -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
)