OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libm/] [common/] [s_rint.c] - Blame information for rev 345

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
 
2
/* @(#)s_rint.c 5.1 93/09/24 */
3
/*
4
 * ====================================================
5
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6
 *
7
 * Developed at SunPro, a Sun Microsystems, Inc. business.
8
 * Permission to use, copy, modify, and distribute this
9
 * software is freely granted, provided that this notice
10
 * is preserved.
11
 * ====================================================
12
 */
13
/*
14
FUNCTION
15
<<rint>>, <<rintf>>--round to integer
16
INDEX
17
        rint
18
INDEX
19
        rintf
20
 
21
ANSI_SYNOPSIS
22
        #include <math.h>
23
        double rint(double <[x]>);
24
        float rintf(float <[x]>);
25
 
26
DESCRIPTION
27
        The <<rint>> functions round their argument to an integer value in
28
        floating-point format, using the current rounding direction.  They
29
        raise the "inexact" floating-point exception if the result differs
30
        in value from the argument.  See the <<nearbyint>> functions for the
31
        same function with the "inexact" floating-point exception never being
32
        raised.  Newlib does not directly support floating-point exceptions.
33
        The <<rint>> functions are written so that the "inexact" exception is
34
        raised in hardware implementations that support it, even though Newlib
35
        does not provide access.
36
 
37
RETURNS
38
<[x]> rounded to an integral value, using the current rounding direction.
39
 
40
PORTABILITY
41
ANSI C, POSIX
42
 
43
SEEALSO
44
<<nearbyint>>, <<round>>
45
 
46
*/
47
 
48
/*
49
 * rint(x)
50
 * Return x rounded to integral value according to the prevailing
51
 * rounding mode.
52
 * Method:
53
 *      Using floating addition.
54
 * Exception:
55
 *      Inexact flag raised if x not equal to rint(x).
56
 */
57
 
58
#include "fdlibm.h"
59
 
60
#ifndef _DOUBLE_IS_32BITS
61
 
62
#ifdef __STDC__
63
static const double
64
#else
65
static double
66
#endif
67
TWO52[2]={
68
  4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
69
 -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
70
};
71
 
72
#ifdef __STDC__
73
        double rint(double x)
74
#else
75
        double rint(x)
76
        double x;
77
#endif
78
{
79
        __int32_t i0,j0,sx;
80
        __uint32_t i,i1;
81
        double t;
82
        volatile double w;
83
        EXTRACT_WORDS(i0,i1,x);
84
        sx = (i0>>31)&1;
85
        j0 = ((i0>>20)&0x7ff)-0x3ff;
86
        if(j0<20) {
87
            if(j0<0) {
88
                if(((i0&0x7fffffff)|i1)==0) return x;
89
                i1 |= (i0&0x0fffff);
90
                i0 &= 0xfffe0000;
91
                i0 |= ((i1|-i1)>>12)&0x80000;
92
                SET_HIGH_WORD(x,i0);
93
                w = TWO52[sx]+x;
94
                t =  w-TWO52[sx];
95
                GET_HIGH_WORD(i0,t);
96
                SET_HIGH_WORD(t,(i0&0x7fffffff)|(sx<<31));
97
                return t;
98
            } else {
99
                i = (0x000fffff)>>j0;
100
                if(((i0&i)|i1)==0) return x; /* x is integral */
101
                i>>=1;
102
                if(((i0&i)|i1)!=0) {
103
                    if(j0==19) i1 = 0x40000000; else
104
                    i0 = (i0&(~i))|((0x20000)>>j0);
105
                }
106
            }
107
        } else if (j0>51) {
108
            if(j0==0x400) return x+x;   /* inf or NaN */
109
            else return x;              /* x is integral */
110
        } else {
111
            i = ((__uint32_t)(0xffffffff))>>(j0-20);
112
            if((i1&i)==0) return x;      /* x is integral */
113
            i>>=1;
114
            if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-20));
115
        }
116
        INSERT_WORDS(x,i0,i1);
117
        w = TWO52[sx]+x;
118
        return w-TWO52[sx];
119
}
120
 
121
#endif /* _DOUBLE_IS_32BITS */
122
 
123
 
124
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.