1 | /* nextafterq.c -- __float128 version of s_nextafter.c. |
2 | * Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz. |
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 <errno.h> |
17 | #include "quadmath-imp.h" |
18 | |
19 | __float128 |
20 | nextafterq (__float128 x, __float128 y) |
21 | { |
22 | int64_t hx,hy,ix,iy; |
23 | uint64_t lx,ly; |
24 | |
25 | GET_FLT128_WORDS64(hx,lx,x); |
26 | GET_FLT128_WORDS64(hy,ly,y); |
27 | ix = hx&0x7fffffffffffffffLL; /* |x| */ |
28 | iy = hy&0x7fffffffffffffffLL; /* |y| */ |
29 | |
30 | if(((ix>=0x7fff000000000000LL)&&((ix-0x7fff000000000000LL)|lx)!=0) || /* x is nan */ |
31 | ((iy>=0x7fff000000000000LL)&&((iy-0x7fff000000000000LL)|ly)!=0)) /* y is nan */ |
32 | return x+y; |
33 | if(x==y) return y; /* x=y, return y */ |
34 | if((ix|lx)==0) { /* x == 0 */ |
35 | SET_FLT128_WORDS64(x,hy&0x8000000000000000ULL,1);/* return +-minsubnormal */ |
36 | |
37 | /* here we should raise an underflow flag */ |
38 | return x; |
39 | } |
40 | if(hx>=0) { /* x > 0 */ |
41 | if(hx>hy||((hx==hy)&&(lx>ly))) { /* x > y, x -= ulp */ |
42 | if(lx==0) hx--; |
43 | lx--; |
44 | } else { /* x < y, x += ulp */ |
45 | lx++; |
46 | if(lx==0) hx++; |
47 | } |
48 | } else { /* x < 0 */ |
49 | if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){/* x < y, x -= ulp */ |
50 | if(lx==0) hx--; |
51 | lx--; |
52 | } else { /* x > y, x += ulp */ |
53 | lx++; |
54 | if(lx==0) hx++; |
55 | } |
56 | } |
57 | hy = hx&0x7fff000000000000LL; |
58 | if(hy==0x7fff000000000000LL) { |
59 | __float128 u = x + x; /* overflow */ |
60 | math_force_eval (u); |
61 | errno = ERANGE; |
62 | } |
63 | if(hy==0) { |
64 | __float128 u = x*x; /* underflow */ |
65 | math_force_eval (u); /* raise underflow flag */ |
66 | errno = ERANGE; |
67 | } |
68 | SET_FLT128_WORDS64(x,hx,lx); |
69 | return x; |
70 | } |
71 | |