libport: Move rint fallback implementations from msvcrt to libport.

Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alex Henrie 2017-11-06 21:01:13 -05:00 committed by Alexandre Julliard
parent 6bae0a003e
commit 06d9c7e25e
5 changed files with 92 additions and 24 deletions

View File

@ -35,6 +35,7 @@
*/ */
#include "config.h" #include "config.h"
#include "wine/port.h"
#include <stdarg.h> #include <stdarg.h>
#include <math.h> #include <math.h>

View File

@ -2604,11 +2604,7 @@ LDOUBLE CDECL MSVCR120_log2l(LDOUBLE x)
*/ */
double CDECL MSVCR120_rint(double x) double CDECL MSVCR120_rint(double x)
{ {
#ifdef HAVE_RINT
return rint(x); return rint(x);
#else
return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
#endif
} }
/********************************************************************* /*********************************************************************
@ -2616,11 +2612,7 @@ double CDECL MSVCR120_rint(double x)
*/ */
float CDECL MSVCR120_rintf(float x) float CDECL MSVCR120_rintf(float x)
{ {
#ifdef HAVE_RINTF
return rintf(x); return rintf(x);
#else
return MSVCR120_rint(x);
#endif
} }
/********************************************************************* /*********************************************************************
@ -2636,11 +2628,7 @@ LDOUBLE CDECL MSVCR120_rintl(LDOUBLE x)
*/ */
MSVCRT_long CDECL MSVCR120_lrint(double x) MSVCRT_long CDECL MSVCR120_lrint(double x)
{ {
#ifdef HAVE_LRINT
return lrint(x); return lrint(x);
#else
return MSVCR120_rint(x);
#endif
} }
/********************************************************************* /*********************************************************************
@ -2648,11 +2636,7 @@ MSVCRT_long CDECL MSVCR120_lrint(double x)
*/ */
MSVCRT_long CDECL MSVCR120_lrintf(float x) MSVCRT_long CDECL MSVCR120_lrintf(float x)
{ {
#ifdef HAVE_LRINTF
return lrintf(x); return lrintf(x);
#else
return MSVCR120_lrint(x);
#endif
} }
/********************************************************************* /*********************************************************************
@ -2668,11 +2652,7 @@ MSVCRT_long CDECL MSVCR120_lrintl(LDOUBLE x)
*/ */
MSVCRT_longlong CDECL MSVCR120_llrint(double x) MSVCRT_longlong CDECL MSVCR120_llrint(double x)
{ {
#ifdef HAVE_LLRINT
return llrint(x); return llrint(x);
#else
return MSVCR120_rint(x);
#endif
} }
/********************************************************************* /*********************************************************************
@ -2680,11 +2660,7 @@ MSVCRT_longlong CDECL MSVCR120_llrint(double x)
*/ */
MSVCRT_longlong CDECL MSVCR120_llrintf(float x) MSVCRT_longlong CDECL MSVCR120_llrintf(float x)
{ {
#ifdef HAVE_LLRINTF
return llrintf(x); return llrintf(x);
#else
return MSVCR120_llrint(x);
#endif
} }
/********************************************************************* /*********************************************************************

View File

@ -272,6 +272,22 @@ int isinf(double x);
int isnan(double x); int isnan(double x);
#endif #endif
#ifndef HAVE_LLRINT
__int64 llrint(double x);
#endif
#ifndef HAVE_LLRINTF
__int64 llrintf(float x);
#endif
#ifndef HAVE_LRINT
long lrint(double x);
#endif
#ifndef HAVE_LRINTF
long lrintf(float x);
#endif
#ifndef HAVE_LSTAT #ifndef HAVE_LSTAT
int lstat(const char *file_name, struct stat *buf); int lstat(const char *file_name, struct stat *buf);
#endif /* HAVE_LSTAT */ #endif /* HAVE_LSTAT */
@ -308,6 +324,14 @@ ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
int readlink( const char *path, char *buf, size_t size ); int readlink( const char *path, char *buf, size_t size );
#endif /* HAVE_READLINK */ #endif /* HAVE_READLINK */
#ifndef HAVE_RINT
double rint(double x);
#endif
#ifndef HAVE_RINTF
float rintf(float x);
#endif
#ifndef HAVE_STATVFS #ifndef HAVE_STATVFS
int statvfs( const char *path, struct statvfs *buf ); int statvfs( const char *path, struct statvfs *buf );
#endif #endif

View File

@ -96,6 +96,7 @@ C_SRCS = \
pread.c \ pread.c \
pwrite.c \ pwrite.c \
readlink.c \ readlink.c \
rint.c \
spawn.c \ spawn.c \
statvfs.c \ statvfs.c \
strcasecmp.c \ strcasecmp.c \

66
libs/port/rint.c Normal file
View File

@ -0,0 +1,66 @@
/*
* rint family
*
* Copyright 2017 Alex Henrie
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include "wine/port.h"
#include <math.h>
#ifndef HAVE_RINT
double rint(double x)
{
return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
}
#endif
#ifndef HAVE_RINTF
float rintf(float x)
{
return rintf(x);
}
#endif
#ifndef HAVE_LRINT
long lrint(double x)
{
return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
}
#endif
#ifndef HAVE_LRINTF
long lrintf(float x)
{
return lrint(x);
}
#endif
#ifndef HAVE_LLRINT
__int64 llrint(double x)
{
return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
}
#endif
#ifndef HAVE_LLRINTF
__int64 llrintf(float x)
{
return llrint(x);
}
#endif