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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libm/] [math/] [e_fmod.c] - Diff between revs 148 and 158

Only display areas with differences | Details | Blame | View Log

Rev 148 Rev 158
 
 
/* @(#)e_fmod.c 5.1 93/09/24 */
/* @(#)e_fmod.c 5.1 93/09/24 */
/*
/*
 * ====================================================
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * software is freely granted, provided that this notice
 * is preserved.
 * is preserved.
 * ====================================================
 * ====================================================
 */
 */
 
 
/*
/*
 * __ieee754_fmod(x,y)
 * __ieee754_fmod(x,y)
 * Return x mod y in exact arithmetic
 * Return x mod y in exact arithmetic
 * Method: shift and subtract
 * Method: shift and subtract
 */
 */
 
 
#include "fdlibm.h"
#include "fdlibm.h"
 
 
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
 
 
#ifdef __STDC__
#ifdef __STDC__
static const double one = 1.0, Zero[] = {0.0, -0.0,};
static const double one = 1.0, Zero[] = {0.0, -0.0,};
#else
#else
static double one = 1.0, Zero[] = {0.0, -0.0,};
static double one = 1.0, Zero[] = {0.0, -0.0,};
#endif
#endif
 
 
#ifdef __STDC__
#ifdef __STDC__
        double __ieee754_fmod(double x, double y)
        double __ieee754_fmod(double x, double y)
#else
#else
        double __ieee754_fmod(x,y)
        double __ieee754_fmod(x,y)
        double x,y ;
        double x,y ;
#endif
#endif
{
{
        __int32_t n,hx,hy,hz,ix,iy,sx,i;
        __int32_t n,hx,hy,hz,ix,iy,sx,i;
        __uint32_t lx,ly,lz;
        __uint32_t lx,ly,lz;
 
 
        EXTRACT_WORDS(hx,lx,x);
        EXTRACT_WORDS(hx,lx,x);
        EXTRACT_WORDS(hy,ly,y);
        EXTRACT_WORDS(hy,ly,y);
        sx = hx&0x80000000;             /* sign of x */
        sx = hx&0x80000000;             /* sign of x */
        hx ^=sx;                /* |x| */
        hx ^=sx;                /* |x| */
        hy &= 0x7fffffff;       /* |y| */
        hy &= 0x7fffffff;       /* |y| */
 
 
    /* purge off exception values */
    /* purge off exception values */
        if((hy|ly)==0||(hx>=0x7ff00000)||        /* y=0,or x not finite */
        if((hy|ly)==0||(hx>=0x7ff00000)||        /* y=0,or x not finite */
          ((hy|((ly|-ly)>>31))>0x7ff00000))     /* or y is NaN */
          ((hy|((ly|-ly)>>31))>0x7ff00000))     /* or y is NaN */
            return (x*y)/(x*y);
            return (x*y)/(x*y);
        if(hx<=hy) {
        if(hx<=hy) {
            if((hx<hy)||(lx<ly)) return x;      /* |x|<|y| return x */
            if((hx<hy)||(lx<ly)) return x;      /* |x|<|y| return x */
            if(lx==ly)
            if(lx==ly)
                return Zero[(__uint32_t)sx>>31];        /* |x|=|y| return x*0*/
                return Zero[(__uint32_t)sx>>31];        /* |x|=|y| return x*0*/
        }
        }
 
 
    /* determine ix = ilogb(x) */
    /* determine ix = ilogb(x) */
        if(hx<0x00100000) {     /* subnormal x */
        if(hx<0x00100000) {     /* subnormal x */
            if(hx==0) {
            if(hx==0) {
                for (ix = -1043, i=lx; i>0; i<<=1) ix -=1;
                for (ix = -1043, i=lx; i>0; i<<=1) ix -=1;
            } else {
            } else {
                for (ix = -1022,i=(hx<<11); i>0; i<<=1) ix -=1;
                for (ix = -1022,i=(hx<<11); i>0; i<<=1) ix -=1;
            }
            }
        } else ix = (hx>>20)-1023;
        } else ix = (hx>>20)-1023;
 
 
    /* determine iy = ilogb(y) */
    /* determine iy = ilogb(y) */
        if(hy<0x00100000) {     /* subnormal y */
        if(hy<0x00100000) {     /* subnormal y */
            if(hy==0) {
            if(hy==0) {
                for (iy = -1043, i=ly; i>0; i<<=1) iy -=1;
                for (iy = -1043, i=ly; i>0; i<<=1) iy -=1;
            } else {
            } else {
                for (iy = -1022,i=(hy<<11); i>0; i<<=1) iy -=1;
                for (iy = -1022,i=(hy<<11); i>0; i<<=1) iy -=1;
            }
            }
        } else iy = (hy>>20)-1023;
        } else iy = (hy>>20)-1023;
 
 
    /* set up {hx,lx}, {hy,ly} and align y to x */
    /* set up {hx,lx}, {hy,ly} and align y to x */
        if(ix >= -1022)
        if(ix >= -1022)
            hx = 0x00100000|(0x000fffff&hx);
            hx = 0x00100000|(0x000fffff&hx);
        else {          /* subnormal x, shift x to normal */
        else {          /* subnormal x, shift x to normal */
            n = -1022-ix;
            n = -1022-ix;
            if(n<=31) {
            if(n<=31) {
                hx = (hx<<n)|(lx>>(32-n));
                hx = (hx<<n)|(lx>>(32-n));
                lx <<= n;
                lx <<= n;
            } else {
            } else {
                hx = lx<<(n-32);
                hx = lx<<(n-32);
                lx = 0;
                lx = 0;
            }
            }
        }
        }
        if(iy >= -1022)
        if(iy >= -1022)
            hy = 0x00100000|(0x000fffff&hy);
            hy = 0x00100000|(0x000fffff&hy);
        else {          /* subnormal y, shift y to normal */
        else {          /* subnormal y, shift y to normal */
            n = -1022-iy;
            n = -1022-iy;
            if(n<=31) {
            if(n<=31) {
                hy = (hy<<n)|(ly>>(32-n));
                hy = (hy<<n)|(ly>>(32-n));
                ly <<= n;
                ly <<= n;
            } else {
            } else {
                hy = ly<<(n-32);
                hy = ly<<(n-32);
                ly = 0;
                ly = 0;
            }
            }
        }
        }
 
 
    /* fix point fmod */
    /* fix point fmod */
        n = ix - iy;
        n = ix - iy;
        while(n--) {
        while(n--) {
            hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
            hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
            if(hz<0){hx = hx+hx+(lx>>31); lx = lx+lx;}
            if(hz<0){hx = hx+hx+(lx>>31); lx = lx+lx;}
            else {
            else {
                if((hz|lz)==0)           /* return sign(x)*0 */
                if((hz|lz)==0)           /* return sign(x)*0 */
                    return Zero[(__uint32_t)sx>>31];
                    return Zero[(__uint32_t)sx>>31];
                hx = hz+hz+(lz>>31); lx = lz+lz;
                hx = hz+hz+(lz>>31); lx = lz+lz;
            }
            }
        }
        }
        hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
        hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
        if(hz>=0) {hx=hz;lx=lz;}
        if(hz>=0) {hx=hz;lx=lz;}
 
 
    /* convert back to floating value and restore the sign */
    /* convert back to floating value and restore the sign */
        if((hx|lx)==0)                   /* return sign(x)*0 */
        if((hx|lx)==0)                   /* return sign(x)*0 */
            return Zero[(__uint32_t)sx>>31];
            return Zero[(__uint32_t)sx>>31];
        while(hx<0x00100000) {          /* normalize x */
        while(hx<0x00100000) {          /* normalize x */
            hx = hx+hx+(lx>>31); lx = lx+lx;
            hx = hx+hx+(lx>>31); lx = lx+lx;
            iy -= 1;
            iy -= 1;
        }
        }
        if(iy>= -1022) {        /* normalize output */
        if(iy>= -1022) {        /* normalize output */
            hx = ((hx-0x00100000)|((iy+1023)<<20));
            hx = ((hx-0x00100000)|((iy+1023)<<20));
            INSERT_WORDS(x,hx|sx,lx);
            INSERT_WORDS(x,hx|sx,lx);
        } else {                /* subnormal output */
        } else {                /* subnormal output */
            n = -1022 - iy;
            n = -1022 - iy;
            if(n<=20) {
            if(n<=20) {
                lx = (lx>>n)|((__uint32_t)hx<<(32-n));
                lx = (lx>>n)|((__uint32_t)hx<<(32-n));
                hx >>= n;
                hx >>= n;
            } else if (n<=31) {
            } else if (n<=31) {
                lx = (hx<<(32-n))|(lx>>n); hx = sx;
                lx = (hx<<(32-n))|(lx>>n); hx = sx;
            } else {
            } else {
                lx = hx>>(n-32); hx = sx;
                lx = hx>>(n-32); hx = sx;
            }
            }
            INSERT_WORDS(x,hx|sx,lx);
            INSERT_WORDS(x,hx|sx,lx);
            x *= one;           /* create necessary signal */
            x *= one;           /* create necessary signal */
        }
        }
        return x;               /* exact output */
        return x;               /* exact output */
}
}
 
 
#endif /* defined(_DOUBLE_IS_32BITS) */
#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.