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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libm/] [math/] [sf_floor.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 lampret
/* 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;
42
        GET_FLOAT_WORD(i0,x);
43
        j0 = ((i0>>23)&0xff)-0x7f;
44
        if(j0<23) {
45
            if(j0<0) {   /* raise inexact if x != 0 */
46
                if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */
47
                    if(i0>=0) {i0=0;}
48
                    else if((i0&0x7fffffff)!=0)
49
                        { i0=0xbf800000;}
50
                }
51
            } else {
52
                i = (0x007fffff)>>j0;
53
                if((i0&i)==0) return x; /* x is integral */
54
                if(huge+x>(float)0.0) { /* raise inexact flag */
55
                    if(i0<0) i0 += (0x00800000)>>j0;
56
                    i0 &= (~i);
57
                }
58
            }
59
        } else {
60
            if(j0==0x80) return x+x;    /* inf or NaN */
61
            else return x;              /* x is integral */
62
        }
63
        SET_FLOAT_WORD(x,i0);
64
        return x;
65
}
66
 
67
#ifdef _DOUBLE_IS_32BITS
68
 
69
#ifdef __STDC__
70
        double floor(double x)
71
#else
72
        double floor(x)
73
        double x;
74
#endif
75
{
76
        return (double) floorf((float) x);
77
}
78
 
79
#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.