A rint() implementation.

This commit is contained in:
Ben Gras 2007-12-14 11:59:54 +00:00
parent bd489b6c0b
commit 50fa859819
4 changed files with 16 additions and 15 deletions

View file

@ -30,6 +30,7 @@ _PROTOTYPE( double log, (double _x) );
_PROTOTYPE( double log10, (double _x) );
_PROTOTYPE( double modf, (double _x, double *_iptr) );
_PROTOTYPE( double pow, (double _x, double _y) );
_PROTOTYPE( double rint, (double _x) );
_PROTOTYPE( double sin, (double _x) );
_PROTOTYPE( double sinh, (double _x) );
_PROTOTYPE( double sqrt, (double _x) );

View file

@ -17,6 +17,7 @@ libc_FILES=" \
log.c \
log10.c \
pow.c \
s_rint.c \
sin.c \
sinh.c \
sqrt.c \

View file

@ -18,7 +18,7 @@
#define _MATH_PRIVATE_H_
#include <sys/types.h>
#include <machine/endian.h>
#include <net/hton.h>
/*
* The original fdlibm code used statements like:
@ -38,29 +38,29 @@
* ints.
*/
#if BYTE_ORDER == BIG_ENDIAN
#if BIG_ENDIAN
typedef union
{
double value;
struct
{
u_int32_t msw;
u_int32_t lsw;
u32_t msw;
u32_t lsw;
} parts;
} ieee_double_shape_type;
#endif
#if BYTE_ORDER == LITTLE_ENDIAN
#if LITTLE_ENDIAN
typedef union
{
double value;
struct
{
u_int32_t lsw;
u_int32_t msw;
u32_t lsw;
u32_t msw;
} parts;
} ieee_double_shape_type;
@ -154,6 +154,8 @@ do { \
(d) = sf_u.value; \
} while (0)
#if 0
#ifdef _COMPLEX_H
/*
* Inline functions that can be used to construct complex values.
@ -269,4 +271,6 @@ float __kernel_cosdf(double);
float __kernel_tandf(double,int);
int __kernel_rem_pio2f(float*,float*,int,int,int,const int*);
#endif
#endif /* !_MATH_PRIVATE_H_ */

View file

@ -10,10 +10,6 @@
* ====================================================
*/
#ifndef lint
static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_rint.c,v 1.11.2.1 2007/06/14 05:16:44 bde Exp $";
#endif
/*
* rint(x)
* Return x rounded to integral value according to the prevailing
@ -24,7 +20,6 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_rint.c,v 1.11.2.1 2007/06/14
* Inexact flag raised if x not equal to rint(x).
*/
#include "math.h"
#include "math_private.h"
static const double
@ -36,8 +31,8 @@ TWO52[2]={
double
rint(double x)
{
int32_t i0,j0,sx;
u_int32_t i,i1;
i32_t i0,j0,sx;
u32_t i,i1;
double w,t;
EXTRACT_WORDS(i0,i1,x);
sx = (i0>>31)&1;
@ -76,7 +71,7 @@ rint(double x)
if(j0==0x400) return x+x; /* inf or NaN */
else return x; /* x is integral */
} else {
i = ((u_int32_t)(0xffffffff))>>(j0-20);
i = ((u32_t)(0xffffffff))>>(j0-20);
if((i1&i)==0) return x; /* x is integral */
i>>=1;
if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-20));