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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1010 ivang
/* sf_modf.c -- float version of s_modf.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 one = 1.0;
20
#else
21
static float one = 1.0;
22
#endif
23
 
24
#ifdef __STDC__
25
        float modff(float x, float *iptr)
26
#else
27
        float modff(x, iptr)
28
        float x,*iptr;
29
#endif
30
{
31
        __int32_t i0,j0;
32
        __uint32_t i;
33
        GET_FLOAT_WORD(i0,x);
34
        j0 = ((i0>>23)&0xff)-0x7f;      /* exponent of x */
35
        if(j0<23) {                     /* integer part in x */
36
            if(j0<0) {                   /* |x|<1 */
37
                SET_FLOAT_WORD(*iptr,i0&0x80000000);    /* *iptr = +-0 */
38
                return x;
39
            } else {
40
                i = (0x007fffff)>>j0;
41
                if((i0&i)==0) {                  /* x is integral */
42
                    __uint32_t ix;
43
                    *iptr = x;
44
                    GET_FLOAT_WORD(ix,x);
45
                    SET_FLOAT_WORD(x,ix&0x80000000);    /* return +-0 */
46
                    return x;
47
                } else {
48
                    SET_FLOAT_WORD(*iptr,i0&(~i));
49
                    return x - *iptr;
50
                }
51
            }
52
        } else {                        /* no fraction part */
53
            __uint32_t ix;
54
            *iptr = x*one;
55
            GET_FLOAT_WORD(ix,x);
56
            SET_FLOAT_WORD(x,ix&0x80000000);    /* return +-0 */
57
            return x;
58
        }
59
}
60
 
61
#ifdef _DOUBLE_IS_32BITS
62
 
63
#ifdef __STDC__
64
        double modf(double x, double *iptr)
65
#else
66
        double modf(x, iptr)
67
        double x,*iptr;
68
#endif
69
{
70
        return (double) modff((float) x, (float *) iptr);
71
}
72
 
73
#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.