A rint() implementation.
This commit is contained in:
parent
bd489b6c0b
commit
50fa859819
4 changed files with 16 additions and 15 deletions
|
@ -30,6 +30,7 @@ _PROTOTYPE( double log, (double _x) );
|
||||||
_PROTOTYPE( double log10, (double _x) );
|
_PROTOTYPE( double log10, (double _x) );
|
||||||
_PROTOTYPE( double modf, (double _x, double *_iptr) );
|
_PROTOTYPE( double modf, (double _x, double *_iptr) );
|
||||||
_PROTOTYPE( double pow, (double _x, double _y) );
|
_PROTOTYPE( double pow, (double _x, double _y) );
|
||||||
|
_PROTOTYPE( double rint, (double _x) );
|
||||||
_PROTOTYPE( double sin, (double _x) );
|
_PROTOTYPE( double sin, (double _x) );
|
||||||
_PROTOTYPE( double sinh, (double _x) );
|
_PROTOTYPE( double sinh, (double _x) );
|
||||||
_PROTOTYPE( double sqrt, (double _x) );
|
_PROTOTYPE( double sqrt, (double _x) );
|
||||||
|
|
|
@ -17,6 +17,7 @@ libc_FILES=" \
|
||||||
log.c \
|
log.c \
|
||||||
log10.c \
|
log10.c \
|
||||||
pow.c \
|
pow.c \
|
||||||
|
s_rint.c \
|
||||||
sin.c \
|
sin.c \
|
||||||
sinh.c \
|
sinh.c \
|
||||||
sqrt.c \
|
sqrt.c \
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#define _MATH_PRIVATE_H_
|
#define _MATH_PRIVATE_H_
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <machine/endian.h>
|
#include <net/hton.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The original fdlibm code used statements like:
|
* The original fdlibm code used statements like:
|
||||||
|
@ -38,29 +38,29 @@
|
||||||
* ints.
|
* ints.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if BYTE_ORDER == BIG_ENDIAN
|
#if BIG_ENDIAN
|
||||||
|
|
||||||
typedef union
|
typedef union
|
||||||
{
|
{
|
||||||
double value;
|
double value;
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
u_int32_t msw;
|
u32_t msw;
|
||||||
u_int32_t lsw;
|
u32_t lsw;
|
||||||
} parts;
|
} parts;
|
||||||
} ieee_double_shape_type;
|
} ieee_double_shape_type;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
#if LITTLE_ENDIAN
|
||||||
|
|
||||||
typedef union
|
typedef union
|
||||||
{
|
{
|
||||||
double value;
|
double value;
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
u_int32_t lsw;
|
u32_t lsw;
|
||||||
u_int32_t msw;
|
u32_t msw;
|
||||||
} parts;
|
} parts;
|
||||||
} ieee_double_shape_type;
|
} ieee_double_shape_type;
|
||||||
|
|
||||||
|
@ -154,6 +154,8 @@ do { \
|
||||||
(d) = sf_u.value; \
|
(d) = sf_u.value; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
#ifdef _COMPLEX_H
|
#ifdef _COMPLEX_H
|
||||||
/*
|
/*
|
||||||
* Inline functions that can be used to construct complex values.
|
* Inline functions that can be used to construct complex values.
|
||||||
|
@ -269,4 +271,6 @@ float __kernel_cosdf(double);
|
||||||
float __kernel_tandf(double,int);
|
float __kernel_tandf(double,int);
|
||||||
int __kernel_rem_pio2f(float*,float*,int,int,int,const int*);
|
int __kernel_rem_pio2f(float*,float*,int,int,int,const int*);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* !_MATH_PRIVATE_H_ */
|
#endif /* !_MATH_PRIVATE_H_ */
|
||||||
|
|
|
@ -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)
|
* rint(x)
|
||||||
* Return x rounded to integral value according to the prevailing
|
* 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).
|
* Inexact flag raised if x not equal to rint(x).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "math.h"
|
|
||||||
#include "math_private.h"
|
#include "math_private.h"
|
||||||
|
|
||||||
static const double
|
static const double
|
||||||
|
@ -36,8 +31,8 @@ TWO52[2]={
|
||||||
double
|
double
|
||||||
rint(double x)
|
rint(double x)
|
||||||
{
|
{
|
||||||
int32_t i0,j0,sx;
|
i32_t i0,j0,sx;
|
||||||
u_int32_t i,i1;
|
u32_t i,i1;
|
||||||
double w,t;
|
double w,t;
|
||||||
EXTRACT_WORDS(i0,i1,x);
|
EXTRACT_WORDS(i0,i1,x);
|
||||||
sx = (i0>>31)&1;
|
sx = (i0>>31)&1;
|
||||||
|
@ -76,7 +71,7 @@ rint(double x)
|
||||||
if(j0==0x400) return x+x; /* inf or NaN */
|
if(j0==0x400) return x+x; /* inf or NaN */
|
||||||
else return x; /* x is integral */
|
else return x; /* x is integral */
|
||||||
} else {
|
} else {
|
||||||
i = ((u_int32_t)(0xffffffff))>>(j0-20);
|
i = ((u32_t)(0xffffffff))>>(j0-20);
|
||||||
if((i1&i)==0) return x; /* x is integral */
|
if((i1&i)==0) return x; /* x is integral */
|
||||||
i>>=1;
|
i>>=1;
|
||||||
if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-20));
|
if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-20));
|
||||||
|
|
Loading…
Reference in a new issue