]>
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> |
b4d5b8b0 | 25 | #include <math-barriers.h> |
3e336a87 | 26 | #include <math_private.h> |
c776b3d7 | 27 | #include <float.h> |
dfd2257a | 28 | |
8db21882 | 29 | float __nexttowardf(float x, long double y) |
dfd2257a | 30 | { |
abfbdde1 | 31 | int32_t hx,hy,ix,iy; |
24ab7723 | 32 | uint32_t ly; |
dfd2257a UD |
33 | |
34 | GET_FLOAT_WORD(hx,x); | |
abfbdde1 | 35 | EXTRACT_WORDS(hy,ly,y); |
dfd2257a | 36 | ix = hx&0x7fffffff; /* |x| */ |
abfbdde1 | 37 | iy = hy&0x7fffffff; /* |y| */ |
dfd2257a | 38 | |
636ccfc8 | 39 | if((ix>0x7f800000) || /* x is nan */ |
d03db7f0 | 40 | ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */ |
dfd2257a UD |
41 | return x+y; |
42 | if((long double) x==y) return y; /* x=y, return y */ | |
43 | if(ix==0) { /* x == 0 */ | |
3e336a87 | 44 | float u; |
24ab7723 | 45 | SET_FLOAT_WORD(x,(uint32_t)(hy&0x80000000)|1);/* return +-minsub*/ |
3e336a87 UD |
46 | u = math_opt_barrier (x); |
47 | u = u * u; | |
48 | math_force_eval (u); /* raise underflow flag */ | |
49 | return x; | |
dfd2257a UD |
50 | } |
51 | if(hx>=0) { /* x > 0 */ | |
7cb029ee | 52 | if(x > y) /* x -= ulp */ |
dfd2257a | 53 | hx -= 1; |
abfbdde1 | 54 | else /* x < y, x += ulp */ |
dfd2257a | 55 | hx += 1; |
dfd2257a | 56 | } else { /* x < 0 */ |
7cb029ee | 57 | if(x < y) /* x -= ulp */ |
dfd2257a | 58 | hx -= 1; |
abfbdde1 | 59 | else /* x > y, x += ulp */ |
dfd2257a | 60 | hx += 1; |
dfd2257a UD |
61 | } |
62 | hy = hx&0x7f800000; | |
c776b3d7 | 63 | if(hy>=0x7f800000) { |
59a63cca JM |
64 | float u = x+x; /* overflow */ |
65 | math_force_eval (u); | |
85422c2a | 66 | __set_errno (ERANGE); |
c776b3d7 | 67 | } |
3e336a87 UD |
68 | if(hy<0x00800000) { |
69 | float u = x*x; /* underflow */ | |
70 | math_force_eval (u); /* raise underflow flag */ | |
85422c2a | 71 | __set_errno (ERANGE); |
dfd2257a UD |
72 | } |
73 | SET_FLOAT_WORD(x,hx); | |
74 | return x; | |
75 | } | |
36fe9ac9 | 76 | weak_alias (__nexttowardf, nexttowardf) |