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#if defined(LIBM_SCCS) && !defined(lint)
17static char rcsid[] = "$NetBSD: s_nextafterf.c,v 1.4 1995/05/10 20:48:01 jtc Exp $";
18#endif
19
20#include <errno.h>
21#include <math.h>
22#include <math_private.h>
23#include <float.h>
24
25float __nextafterf(float x, float y)
26{
27 int32_t hx,hy,ix,iy;
28
29 GET_FLOAT_WORD(hx,x);
30 GET_FLOAT_WORD(hy,y);
31 ix = hx&0x7fffffff; /* |x| */
32 iy = hy&0x7fffffff; /* |y| */
33
34 if((ix>0x7f800000) || /* x is nan */
35 (iy>0x7f800000)) /* y is nan */
36 return x+y;
37 if(x==y) return y; /* x=y, return y */
38 if(ix==0) { /* x == 0 */
39 float u;
40 SET_FLOAT_WORD(x,(hy&0x80000000)|1);/* return +-minsubnormal */
41 u = math_opt_barrier (x);
42 u = u*u;
43 math_force_eval (u); /* raise underflow flag */
44 return x;
45 }
46 if(hx>=0) { /* x > 0 */
47 if(hx>hy) { /* x > y, x -= ulp */
48 hx -= 1;
49 } else { /* x < y, x += ulp */
50 hx += 1;
51 }
52 } else { /* x < 0 */
53 if(hy>=0||hx>hy){ /* x < y, x -= ulp */
54 hx -= 1;
55 } else { /* x > y, x += ulp */
56 hx += 1;
57 }
58 }
59 hy = hx&0x7f800000;
60 if(hy>=0x7f800000) {
61 float u = x+x; /* overflow */
62 math_force_eval (u);
63 __set_errno (ERANGE);
64 }
65 if(hy<0x00800000) {
66 float u = x*x; /* underflow */
67 math_force_eval (u); /* raise underflow flag */
68 __set_errno (ERANGE);
69 }
70 SET_FLOAT_WORD(x,hx);
71 return x;
72}
73weak_alias (__nextafterf, nextafterf)
74