comparison libquadmath/math/nextafterq.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 04ced10e8804
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* nextafterq.c -- __float128 version of s_nextafter.c. 1 /* s_nextafterl.c -- long double version of s_nextafter.c.
2 * Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz. 2 * Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz.
3 */ 3 */
4 4
5 /* 5 /*
6 * ==================================================== 6 * ====================================================
11 * software is freely granted, provided that this notice 11 * software is freely granted, provided that this notice
12 * is preserved. 12 * is preserved.
13 * ==================================================== 13 * ====================================================
14 */ 14 */
15 15
16 #include <errno.h> 16 #if defined(LIBM_SCCS) && !defined(lint)
17 static char rcsid[] = "$NetBSD: $";
18 #endif
19
20 /* IEEE functions
21 * nextafterq(x,y)
22 * return the next machine floating-point number of x in the
23 * direction toward y.
24 * Special cases:
25 */
26
17 #include "quadmath-imp.h" 27 #include "quadmath-imp.h"
18 28
19 __float128 29 __float128 nextafterq(__float128 x, __float128 y)
20 nextafterq (__float128 x, __float128 y)
21 { 30 {
22 int64_t hx,hy,ix,iy; 31 int64_t hx,hy,ix,iy;
23 uint64_t lx,ly; 32 uint64_t lx,ly;
24 33
25 GET_FLT128_WORDS64(hx,lx,x); 34 GET_FLT128_WORDS64(hx,lx,x);
30 if(((ix>=0x7fff000000000000LL)&&((ix-0x7fff000000000000LL)|lx)!=0) || /* x is nan */ 39 if(((ix>=0x7fff000000000000LL)&&((ix-0x7fff000000000000LL)|lx)!=0) || /* x is nan */
31 ((iy>=0x7fff000000000000LL)&&((iy-0x7fff000000000000LL)|ly)!=0)) /* y is nan */ 40 ((iy>=0x7fff000000000000LL)&&((iy-0x7fff000000000000LL)|ly)!=0)) /* y is nan */
32 return x+y; 41 return x+y;
33 if(x==y) return y; /* x=y, return y */ 42 if(x==y) return y; /* x=y, return y */
34 if((ix|lx)==0) { /* x == 0 */ 43 if((ix|lx)==0) { /* x == 0 */
44 __float128 u;
35 SET_FLT128_WORDS64(x,hy&0x8000000000000000ULL,1);/* return +-minsubnormal */ 45 SET_FLT128_WORDS64(x,hy&0x8000000000000000ULL,1);/* return +-minsubnormal */
36 46 u = math_opt_barrier (x);
37 /* here we should raise an underflow flag */ 47 u = u * u;
48 math_force_eval (u); /* raise underflow flag */
38 return x; 49 return x;
39 } 50 }
40 if(hx>=0) { /* x > 0 */ 51 if(hx>=0) { /* x > 0 */
41 if(hx>hy||((hx==hy)&&(lx>ly))) { /* x > y, x -= ulp */ 52 if(hx>hy||((hx==hy)&&(lx>ly))) { /* x > y, x -= ulp */
42 if(lx==0) hx--; 53 if(lx==0) hx--;
59 __float128 u = x + x; /* overflow */ 70 __float128 u = x + x; /* overflow */
60 math_force_eval (u); 71 math_force_eval (u);
61 errno = ERANGE; 72 errno = ERANGE;
62 } 73 }
63 if(hy==0) { 74 if(hy==0) {
64 __float128 u = x*x; /* underflow */ 75 __float128 u = x*x; /* underflow */
65 math_force_eval (u); /* raise underflow flag */ 76 math_force_eval (u); /* raise underflow flag */
66 errno = ERANGE; 77 errno = ERANGE;
67 } 78 }
68 SET_FLT128_WORDS64(x,hx,lx); 79 SET_FLT128_WORDS64(x,hx,lx);
69 return x; 80 return x;