gonzui


Format: Advanced Search

t2ex/bsd_source/lib/libc/src_bsd/math/s_nextafterf.cbare sourcepermlink (0.02 seconds)

Search this content:

    1: /* s_nextafterf.c -- float version of s_nextafter.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 "math.h"
   17: #include "math_private.h"
   18: 
   19: float
   20: nextafterf(float x, float y)
   21: {
   22:         int32_t hx,hy,ix,iy;
   23: 
   24:         GET_FLOAT_WORD(hx,x);
   25:         GET_FLOAT_WORD(hy,y);
   26:         ix = hx&0x7fffffff;            /* |x| */
   27:         iy = hy&0x7fffffff;            /* |y| */
   28: 
   29:         if((ix>0x7f800000) ||   /* x is nan */ 
   30:            (iy>0x7f800000))     /* y is nan */ 
   31:            return x+y;                         
   32:         if(x==y) return y;             /* x=y, return y */
   33:         if(ix==0) {                            /* x == 0 */
   34:             SET_FLOAT_WORD(x,(hy&0x80000000)|1);/* return +-minsubnormal */
   35:             y = x*x;
   36:             if(y==x) return y; else return x;  /* raise underflow flag */
   37:         } 
   38:         if(hx>=0) {                            /* x > 0 */
   39:             if(hx>hy) {                                /* x > y, x -= ulp */
   40:                 hx -= 1;
   41:             } else {                           /* x < y, x += ulp */
   42:                 hx += 1;
   43:             }
   44:         } else {                               /* x < 0 */
   45:             if(hy>=0||hx>hy){                  /* x < y, x -= ulp */
   46:                 hx -= 1;
   47:             } else {                           /* x > y, x += ulp */
   48:                 hx += 1;
   49:             }
   50:         }
   51:         hy = hx&0x7f800000;
   52:         if(hy>=0x7f800000) return x+x; /* overflow  */
   53:         if(hy<0x00800000) {            /* underflow */
   54:             y = x*x;
   55:             if(y!=x) {         /* raise underflow flag */
   56:                 SET_FLOAT_WORD(y,hx);
   57:                 return y;
   58:             }
   59:         }
   60:         SET_FLOAT_WORD(x,hx);
   61:         return x;
   62: }