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

Subversion Repositories or1k

[/] [or1k/] [branches/] [newlib/] [newlib/] [newlib/] [libm/] [mathfp/] [ef_remainder.c] - Blame information for rev 1766

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

Line No. Rev Author Line
1 56 joel
/* ef_remainder.c -- float version of e_remainder.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 zero = 0.0;
20
#else
21
static float zero = 0.0;
22
#endif
23
 
24
 
25
#ifdef __STDC__
26
        float remainderf(float x, float p)
27
#else
28
        float remainderf(x,p)
29
        float x,p;
30
#endif
31
{
32
        __int32_t hx,hp;
33
        __uint32_t sx;
34
        float p_half;
35
 
36
        GET_FLOAT_WORD(hx,x);
37
        GET_FLOAT_WORD(hp,p);
38
        sx = hx&0x80000000;
39
        hp &= 0x7fffffff;
40
        hx &= 0x7fffffff;
41
 
42
    /* purge off exception values */
43
        if(hp==0) return (x*p)/(x*p);            /* p = 0 */
44
        if((hx>=0x7f800000)||                   /* x not finite */
45
          ((hp>0x7f800000)))                    /* p is NaN */
46
            return (x*p)/(x*p);
47
 
48
 
49
        if (hp<=0x7effffff) x = fmodf(x,p+p);   /* now x < 2p */
50
        if ((hx-hp)==0) return zero*x;
51
        x  = fabsf(x);
52
        p  = fabsf(p);
53
        if (hp<0x01000000) {
54
            if(x+x>p) {
55
                x-=p;
56
                if(x+x>=p) x -= p;
57
            }
58
        } else {
59
            p_half = (float)0.5*p;
60
            if(x>p_half) {
61
                x-=p;
62
                if(x>=p_half) x -= p;
63
            }
64
        }
65
        GET_FLOAT_WORD(hx,x);
66
        SET_FLOAT_WORD(x,hx^sx);
67
        return x;
68
}

powered by: WebSVN 2.1.0

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