OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libm/] [common/] [sf_rint.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 56 joel
/* sf_rint.c -- float version of s_rint.c.
2
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3
 */
4
 
5
/*
6
 * ====================================================
7
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8
 *
9
 * Developed at SunPro, a Sun Microsystems, Inc. business.
10
 * Permission to use, copy, modify, and distribute this
11
 * software is freely granted, provided that this notice
12
 * is preserved.
13
 * ====================================================
14
 */
15
 
16
#include "fdlibm.h"
17
 
18
#ifdef __STDC__
19
static const float
20
#else
21
static float
22
#endif
23
TWO23[2]={
24
  8.3886080000e+06, /* 0x4b000000 */
25
 -8.3886080000e+06, /* 0xcb000000 */
26
};
27
 
28
#ifdef __STDC__
29
        float rintf(float x)
30
#else
31
        float rintf(x)
32
        float x;
33
#endif
34
{
35
        __int32_t i0,j0,sx;
36
        __uint32_t i,i1;
37
        float t;
38
        volatile float w;
39
        GET_FLOAT_WORD(i0,x);
40
        sx = (i0>>31)&1;
41
        j0 = ((i0>>23)&0xff)-0x7f;
42
        if(j0<23) {
43
            if(j0<0) {
44
                if((i0&0x7fffffff)==0) return x;
45
                i1 = (i0&0x07fffff);
46
                i0 &= 0xfff00000;
47
                i0 |= ((i1|-i1)>>9)&0x400000;
48
                SET_FLOAT_WORD(x,i0);
49
                w = TWO23[sx]+x;
50
                t =  w-TWO23[sx];
51
                GET_FLOAT_WORD(i0,t);
52
                SET_FLOAT_WORD(t,(i0&0x7fffffff)|(sx<<31));
53
                return t;
54
            } else {
55
                i = (0x007fffff)>>j0;
56
                if((i0&i)==0) return x; /* x is integral */
57
                i>>=1;
58
                if((i0&i)!=0) i0 = (i0&(~i))|((0x100000)>>j0);
59
            }
60
        } else {
61
            if(j0==0x80) return x+x;    /* inf or NaN */
62
            else return x;              /* x is integral */
63
        }
64
        SET_FLOAT_WORD(x,i0);
65
        w = TWO23[sx]+x;
66
        return w-TWO23[sx];
67
}
68
 
69
#ifdef _DOUBLE_IS_32BITS
70
 
71
#ifdef __STDC__
72
        double rint(double x)
73
#else
74
        double rint(x)
75
        double x;
76
#endif
77
{
78
        return (double) rintf((float) x);
79
}
80
 
81
#endif /* defined(_DOUBLE_IS_32BITS) */

powered by: WebSVN 2.1.0

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