1 /* @(#)s_nextafter.c 5.1 93/09/24 */
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 * Developed at SunPro, a Sun Microsystems, Inc. business.
7 * Permission to use, copy, modify, and distribute this
8 * software is freely granted, provided that this notice
10 * ====================================================
15 * return the next machine floating-point number of x in the
17 * This is for machines which use the same binary type for double and
25 #include "math_private.h"
28 nexttowardf(float x, long double y)
34 EXTRACT_WORDS(hy,ly,y);
35 ix = hx&0x7fffffff; /* |x| */
36 iy = hy&0x7fffffff; /* |y| */
38 if((ix>0x7f800000) || /* x is nan */
39 ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */
41 if((long double) x==y) return y; /* x=y, return y */
42 if(ix==0) { /* x == 0 */
44 SET_FLOAT_WORD(x,(u_int32_t)(hy&0x80000000)|1);/* return +-minsub*/
46 u = u * u; /* raise underflow flag */
49 if(hx>=0) { /* x > 0 */
50 if(hy<0||(ix>>23)>(iy>>20)-0x380
51 || ((ix>>23)==(iy>>20)-0x380
52 && (ix&0x7fffff)>(((hy<<3)|(ly>>29))&0x7fffff))) /* x > y, x -= ulp */
54 else /* x < y, x += ulp */
57 if(hy>=0||(ix>>23)>(iy>>20)-0x380
58 || ((ix>>23)==(iy>>20)-0x380
59 && (ix&0x7fffff)>(((hy<<3)|(ly>>29))&0x7fffff))) /* x < y, x -= ulp */
61 else /* x > y, x += ulp */
66 x = x+x; /* overflow */
70 volatile float u = x*x; /* underflow */