Revert "hurd: Fix abi-tag, following ba90e05"
[glibc.git] / math / s_nexttowardf.c
blobe8c4dd1d8d245e9356e2c4cb85e29967cb823576
1 /* Single precision version of nexttoward.c.
2 Conversion to IEEE single float by Jakub Jelinek, jj@ultra.linux.cz. */
3 /*
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
10 * is preserved.
11 * ====================================================
14 /* IEEE functions
15 * nexttowardf(x,y)
16 * return the next machine floating-point number of x in the
17 * direction toward y.
18 * This is for machines which use the same binary type for double and
19 * long double.
20 * Special cases:
23 #include <math.h>
24 #include <math_private.h>
25 #include <float.h>
27 float __nexttowardf(float x, long double y)
29 int32_t hx,hy,ix,iy;
30 u_int32_t ly;
32 GET_FLOAT_WORD(hx,x);
33 EXTRACT_WORDS(hy,ly,y);
34 ix = hx&0x7fffffff; /* |x| */
35 iy = hy&0x7fffffff; /* |y| */
37 if((ix>0x7f800000) || /* x is nan */
38 ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */
39 return x+y;
40 if((long double) x==y) return y; /* x=y, return y */
41 if(ix==0) { /* x == 0 */
42 float u;
43 SET_FLOAT_WORD(x,(u_int32_t)(hy&0x80000000)|1);/* return +-minsub*/
44 u = math_opt_barrier (x);
45 u = u * u;
46 math_force_eval (u); /* raise underflow flag */
47 return x;
49 if(hx>=0) { /* x > 0 */
50 if(x > y) /* x -= ulp */
51 hx -= 1;
52 else /* x < y, x += ulp */
53 hx += 1;
54 } else { /* x < 0 */
55 if(x < y) /* x -= ulp */
56 hx -= 1;
57 else /* x > y, x += ulp */
58 hx += 1;
60 hy = hx&0x7f800000;
61 if(hy>=0x7f800000) {
62 x = x+x; /* overflow */
63 if (FLT_EVAL_METHOD != 0)
64 /* Force conversion to float. */
65 asm ("" : "+m"(x));
66 return x;
68 if(hy<0x00800000) {
69 float u = x*x; /* underflow */
70 math_force_eval (u); /* raise underflow flag */
72 SET_FLOAT_WORD(x,hx);
73 return x;
75 weak_alias (__nexttowardf, nexttowardf)