]>
Commit | Line | Data |
---|---|---|
abfbdde1 UD |
1 | /* Single precision version of nexttoward.c. |
2 | Conversion to IEEE single float by Jakub Jelinek, jj@ultra.linux.cz. */ | |
dfd2257a UD |
3 | /* |
4 | * ==================================================== | |
5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | |
6 | * | |
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 | * ==================================================== | |
12 | */ | |
13 | ||
abfbdde1 UD |
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: | |
21 | */ | |
dfd2257a | 22 | |
85422c2a | 23 | #include <errno.h> |
9d13fb24 | 24 | #include <math.h> |
3e336a87 | 25 | #include <math_private.h> |
c776b3d7 | 26 | #include <float.h> |
dfd2257a | 27 | |
8db21882 | 28 | float __nexttowardf(float x, long double y) |
dfd2257a | 29 | { |
abfbdde1 UD |
30 | int32_t hx,hy,ix,iy; |
31 | u_int32_t ly; | |
dfd2257a UD |
32 | |
33 | GET_FLOAT_WORD(hx,x); | |
abfbdde1 | 34 | EXTRACT_WORDS(hy,ly,y); |
dfd2257a | 35 | ix = hx&0x7fffffff; /* |x| */ |
abfbdde1 | 36 | iy = hy&0x7fffffff; /* |y| */ |
dfd2257a | 37 | |
636ccfc8 | 38 | if((ix>0x7f800000) || /* x is nan */ |
d03db7f0 | 39 | ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */ |
dfd2257a UD |
40 | return x+y; |
41 | if((long double) x==y) return y; /* x=y, return y */ | |
42 | if(ix==0) { /* x == 0 */ | |
3e336a87 | 43 | float u; |
39d1d4e5 | 44 | SET_FLOAT_WORD(x,(u_int32_t)(hy&0x80000000)|1);/* return +-minsub*/ |
3e336a87 UD |
45 | u = math_opt_barrier (x); |
46 | u = u * u; | |
47 | math_force_eval (u); /* raise underflow flag */ | |
48 | return x; | |
dfd2257a UD |
49 | } |
50 | if(hx>=0) { /* x > 0 */ | |
7cb029ee | 51 | if(x > y) /* x -= ulp */ |
dfd2257a | 52 | hx -= 1; |
abfbdde1 | 53 | else /* x < y, x += ulp */ |
dfd2257a | 54 | hx += 1; |
dfd2257a | 55 | } else { /* x < 0 */ |
7cb029ee | 56 | if(x < y) /* x -= ulp */ |
dfd2257a | 57 | hx -= 1; |
abfbdde1 | 58 | else /* x > y, x += ulp */ |
dfd2257a | 59 | hx += 1; |
dfd2257a UD |
60 | } |
61 | hy = hx&0x7f800000; | |
c776b3d7 | 62 | if(hy>=0x7f800000) { |
59a63cca JM |
63 | float u = x+x; /* overflow */ |
64 | math_force_eval (u); | |
85422c2a | 65 | __set_errno (ERANGE); |
c776b3d7 | 66 | } |
3e336a87 UD |
67 | if(hy<0x00800000) { |
68 | float u = x*x; /* underflow */ | |
69 | math_force_eval (u); /* raise underflow flag */ | |
85422c2a | 70 | __set_errno (ERANGE); |
dfd2257a UD |
71 | } |
72 | SET_FLOAT_WORD(x,hx); | |
73 | return x; | |
74 | } | |
36fe9ac9 | 75 | weak_alias (__nexttowardf, nexttowardf) |