OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libm/] [math/] [e_remainder.c] - Diff between revs 207 and 345

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

Rev 207 Rev 345
 
 
/* @(#)e_remainder.c 5.1 93/09/24 */
/* @(#)e_remainder.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_remainder(x,p)
/* __ieee754_remainder(x,p)
 * Return :
 * Return :
 *      returns  x REM p  =  x - [x/p]*p as if in infinite
 *      returns  x REM p  =  x - [x/p]*p as if in infinite
 *      precise arithmetic, where [x/p] is the (infinite bit)
 *      precise arithmetic, where [x/p] is the (infinite bit)
 *      integer nearest x/p (in half way case choose the even one).
 *      integer nearest x/p (in half way case choose the even one).
 * Method :
 * Method :
 *      Based on fmod() return x-[x/p]chopped*p exactlp.
 *      Based on fmod() return x-[x/p]chopped*p exactlp.
 */
 */
 
 
#include "fdlibm.h"
#include "fdlibm.h"
 
 
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
 
 
#ifdef __STDC__
#ifdef __STDC__
static const double zero = 0.0;
static const double zero = 0.0;
#else
#else
static double zero = 0.0;
static double zero = 0.0;
#endif
#endif
 
 
 
 
#ifdef __STDC__
#ifdef __STDC__
        double __ieee754_remainder(double x, double p)
        double __ieee754_remainder(double x, double p)
#else
#else
        double __ieee754_remainder(x,p)
        double __ieee754_remainder(x,p)
        double x,p;
        double x,p;
#endif
#endif
{
{
        __int32_t hx,hp;
        __int32_t hx,hp;
        __uint32_t sx,lx,lp;
        __uint32_t sx,lx,lp;
        double p_half;
        double p_half;
 
 
        EXTRACT_WORDS(hx,lx,x);
        EXTRACT_WORDS(hx,lx,x);
        EXTRACT_WORDS(hp,lp,p);
        EXTRACT_WORDS(hp,lp,p);
        sx = hx&0x80000000;
        sx = hx&0x80000000;
        hp &= 0x7fffffff;
        hp &= 0x7fffffff;
        hx &= 0x7fffffff;
        hx &= 0x7fffffff;
 
 
    /* purge off exception values */
    /* purge off exception values */
        if((hp|lp)==0) return (x*p)/(x*p);       /* p = 0 */
        if((hp|lp)==0) return (x*p)/(x*p);       /* p = 0 */
        if((hx>=0x7ff00000)||                   /* x not finite */
        if((hx>=0x7ff00000)||                   /* x not finite */
          ((hp>=0x7ff00000)&&                   /* p is NaN */
          ((hp>=0x7ff00000)&&                   /* p is NaN */
          (((hp-0x7ff00000)|lp)!=0)))
          (((hp-0x7ff00000)|lp)!=0)))
            return (x*p)/(x*p);
            return (x*p)/(x*p);
 
 
 
 
        if (hp<=0x7fdfffff) x = __ieee754_fmod(x,p+p);  /* now x < 2p */
        if (hp<=0x7fdfffff) x = __ieee754_fmod(x,p+p);  /* now x < 2p */
        if (((hx-hp)|(lx-lp))==0) return zero*x;
        if (((hx-hp)|(lx-lp))==0) return zero*x;
        x  = fabs(x);
        x  = fabs(x);
        p  = fabs(p);
        p  = fabs(p);
        if (hp<0x00200000) {
        if (hp<0x00200000) {
            if(x+x>p) {
            if(x+x>p) {
                x-=p;
                x-=p;
                if(x+x>=p) x -= p;
                if(x+x>=p) x -= p;
            }
            }
        } else {
        } else {
            p_half = 0.5*p;
            p_half = 0.5*p;
            if(x>p_half) {
            if(x>p_half) {
                x-=p;
                x-=p;
                if(x>=p_half) x -= p;
                if(x>=p_half) x -= p;
            }
            }
        }
        }
        GET_HIGH_WORD(hx,x);
        GET_HIGH_WORD(hx,x);
        SET_HIGH_WORD(x,hx^sx);
        SET_HIGH_WORD(x,hx^sx);
        return x;
        return x;
}
}
 
 
#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.