Back to index

glibc  2.9
s_nextafterf.c
Go to the documentation of this file.
00001 /* s_nextafterf.c -- float version of s_nextafter.c.
00002  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
00003  */
00004 
00005 /*
00006  * ====================================================
00007  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00008  *
00009  * Developed at SunPro, a Sun Microsystems, Inc. business.
00010  * Permission to use, copy, modify, and distribute this
00011  * software is freely granted, provided that this notice
00012  * is preserved.
00013  * ====================================================
00014  */
00015 
00016 #if defined(LIBM_SCCS) && !defined(lint)
00017 static char rcsid[] = "$NetBSD: s_nextafterf.c,v 1.4 1995/05/10 20:48:01 jtc Exp $";
00018 #endif
00019 
00020 #include "math.h"
00021 #include <math_private.h>
00022 #include <float.h>
00023 
00024 #ifdef __STDC__
00025        float __nextafterf(float x, float y)
00026 #else
00027        float __nextafterf(x,y)
00028        float x,y;
00029 #endif
00030 {
00031        int32_t hx,hy,ix,iy;
00032 
00033        GET_FLOAT_WORD(hx,x);
00034        GET_FLOAT_WORD(hy,y);
00035        ix = hx&0x7fffffff;         /* |x| */
00036        iy = hy&0x7fffffff;         /* |y| */
00037 
00038        if((ix>0x7f800000) ||   /* x is nan */
00039           (iy>0x7f800000))     /* y is nan */
00040           return x+y;
00041        if(x==y) return y;          /* x=y, return y */
00042        if(ix==0) {                        /* x == 0 */
00043            float u;
00044            SET_FLOAT_WORD(x,(hy&0x80000000)|1);/* return +-minsubnormal */
00045            u = math_opt_barrier (x);
00046            u = u*u;
00047            math_force_eval (u);           /* raise underflow flag */
00048            return x;
00049        }
00050        if(hx>=0) {                        /* x > 0 */
00051            if(hx>hy) {                           /* x > y, x -= ulp */
00052               hx -= 1;
00053            } else {                       /* x < y, x += ulp */
00054               hx += 1;
00055            }
00056        } else {                           /* x < 0 */
00057            if(hy>=0||hx>hy){                     /* x < y, x -= ulp */
00058               hx -= 1;
00059            } else {                       /* x > y, x += ulp */
00060               hx += 1;
00061            }
00062        }
00063        hy = hx&0x7f800000;
00064        if(hy>=0x7f800000) {
00065          x = x+x;    /* overflow  */
00066          if (FLT_EVAL_METHOD != 0)
00067            asm ("" : "+m"(x));
00068          return x;   /* overflow  */
00069        }
00070        if(hy<0x00800000) {
00071            float u = x*x;                 /* underflow */
00072            math_force_eval (u);           /* raise underflow flag */
00073        }
00074        SET_FLOAT_WORD(x,hx);
00075        return x;
00076 }
00077 weak_alias (__nextafterf, nextafterf)