2.9
[glibc/nacl-glibc.git] / sysdeps / ieee754 / ldbl-128ibm / s_nexttowardf.c
blobcf655fad1670cbfef714889b1026585b82621b35
1 /* s_nexttowardf.c -- float version of s_nextafter.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com
3 * and Jakub Jelinek, jj@ultra.linux.cz.
4 */
6 /*
7 * ====================================================
8 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10 * Developed at SunPro, a Sun Microsystems, Inc. business.
11 * Permission to use, copy, modify, and distribute this
12 * software is freely granted, provided that this notice
13 * is preserved.
14 * ====================================================
17 #if defined(LIBM_SCCS) && !defined(lint)
18 static char rcsid[] = "$NetBSD: $";
19 #endif
21 #include "math.h"
22 #include <math_private.h>
23 #include <math_ldbl_opt.h>
24 #include <float.h>
26 #ifdef __STDC__
27 float __nexttowardf(float x, long double y)
28 #else
29 float __nexttowardf(x,y)
30 float x;
31 long double y;
32 #endif
34 int32_t hx,ix;
35 int64_t hy,iy;
36 u_int64_t ly, uly;
38 GET_FLOAT_WORD(hx,x);
39 GET_LDOUBLE_WORDS64(hy,ly,y);
40 ix = hx&0x7fffffff; /* |x| */
41 iy = hy&0x7fffffffffffffffLL; /* |y| */
42 uly = ly&0x7fffffffffffffffLL; /* |y| */
44 if((ix>0x7f800000) || /* x is nan */
45 ((iy>=0x7ff0000000000000LL)&&((iy-0x7ff0000000000000LL)|uly)!=0))
46 /* y is nan */
47 return x+y;
48 if((long double) x==y) return y; /* x=y, return y */
49 if(ix==0) { /* x == 0 */
50 float u;
51 SET_FLOAT_WORD(x,(u_int32_t)((hy>>32)&0x80000000)|1);/* return +-minsub*/
52 u = math_opt_barrier (x);
53 u = u * u;
54 math_force_eval (u); /* raise underflow flag */
55 return x;
57 if(hx>=0) { /* x > 0 */
58 if(hy<0||(ix>>23)>(iy>>52)-0x380
59 || ((ix>>23)==(iy>>52)-0x380
60 && (ix&0x7fffff)>((hy>>29)&0x7fffff))) {/* x > y, x -= ulp */
61 hx -= 1;
62 } else { /* x < y, x += ulp */
63 hx += 1;
65 } else { /* x < 0 */
66 if(hy>=0||(ix>>23)>(iy>>52)-0x380
67 || ((ix>>23)==(iy>>52)-0x380
68 && (ix&0x7fffff)>((hy>>29)&0x7fffff))) {/* x < y, x -= ulp */
69 hx -= 1;
70 } else { /* x > y, x += ulp */
71 hx += 1;
74 hy = hx&0x7f800000;
75 if(hy>=0x7f800000) {
76 x = x+x; /* overflow */
77 if (FLT_EVAL_METHOD != 0)
78 /* Force conversion to float. */
79 asm ("" : "+m"(x));
80 return x;
82 if(hy<0x00800000) { /* underflow */
83 float u = x*x;
84 math_force_eval (u); /* raise underflow flag */
86 SET_FLOAT_WORD(x,hx);
87 return x;
89 long_double_symbol (libm, __nexttowardf, nexttowardf);