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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libm/] [math/] [sf_floor.c] - Blame information for rev 148

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/* sf_floor.c -- float version of s_floor.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
/*
17
 * floorf(x)
18
 * Return x rounded toward -inf to integral value
19
 * Method:
20
 *      Bit twiddling.
21
 * Exception:
22
 *      Inexact flag raised if x not equal to floorf(x).
23
 */
24
 
25
#include "fdlibm.h"
26
 
27
#ifdef __STDC__
28
static const float huge = 1.0e30;
29
#else
30
static float huge = 1.0e30;
31
#endif
32
 
33
#ifdef __STDC__
34
        float floorf(float x)
35
#else
36
        float floorf(x)
37
        float x;
38
#endif
39
{
40
        __int32_t i0,j0;
41
        __uint32_t i,ix;
42
        GET_FLOAT_WORD(i0,x);
43
        ix = (i0&0x7fffffff);
44
        j0 = (ix>>23)-0x7f;
45
        if(j0<23) {
46
            if(j0<0) {   /* raise inexact if x != 0 */
47
                if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */
48
                    if(i0>=0) {i0=0;}
49
                    else if(!FLT_UWORD_IS_ZERO(ix))
50
                        { i0=0xbf800000;}
51
                }
52
            } else {
53
                i = (0x007fffff)>>j0;
54
                if((i0&i)==0) return x; /* x is integral */
55
                if(huge+x>(float)0.0) { /* raise inexact flag */
56
                    if(i0<0) i0 += (0x00800000)>>j0;
57
                    i0 &= (~i);
58
                }
59
            }
60
        } else {
61
            if(!FLT_UWORD_IS_FINITE(ix)) return x+x;    /* inf or NaN */
62
            else return x;              /* x is integral */
63
        }
64
        SET_FLOAT_WORD(x,i0);
65
        return x;
66
}
67
 
68
#ifdef _DOUBLE_IS_32BITS
69
 
70
#ifdef __STDC__
71
        double floor(double x)
72
#else
73
        double floor(x)
74
        double x;
75
#endif
76
{
77
        return (double) floorf((float) x);
78
}
79
 
80
#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.