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 volatile float t; 23 int32_t hx,hy,ix,iy; 24 25 GET_FLOAT_WORD(hx,x); 26 GET_FLOAT_WORD(hy,y); 27 ix = hx&0x7fffffff; /* |x| */ 28 iy = hy&0x7fffffff; /* |y| */ 29 30 if((ix>0x7f800000) || /* x is nan */ 31 (iy>0x7f800000)) /* y is nan */ 32 return x+y; 33 if(x==y) return y; /* x=y, return y */ 34 if(ix==0) { /* x == 0 */ 35 SET_FLOAT_WORD(x,(hy&0x80000000)|1);/* return +-minsubnormal */ 36 t = x*x; 37 if(t==x) return t; else return x; /* raise underflow flag */ 38 } 39 if(hx>=0) { /* x > 0 */ 40 if(hx>hy) { /* x > y, x -= ulp */ 41 hx -= 1; 42 } else { /* x < y, x += ulp */ 43 hx += 1; 44 } 45 } else { /* x < 0 */ 46 if(hy>=0||hx>hy){ /* x < y, x -= ulp */ 47 hx -= 1; 48 } else { /* x > y, x += ulp */ 49 hx += 1; 50 } 51 } 52 hy = hx&0x7f800000; 53 if(hy>=0x7f800000) return x+x; /* overflow */ 54 if(hy<0x00800000) { /* underflow */ 55 t = x*x; 56 if(t!=x) { /* raise underflow flag */ 57 SET_FLOAT_WORD(y,hx); 58 return y; 59 } 60 } 61 SET_FLOAT_WORD(x,hx); 62 return x; 63 } 64