]>
Commit | Line | Data |
---|---|---|
36fe9ac9 | 1 | /* s_nexttowardf.c -- float version of s_nextafter.c. |
dfd2257a UD |
2 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. |
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 | #if defined(LIBM_SCCS) && !defined(lint) | |
17 | static char rcsid[] = "$NetBSD: $"; | |
18 | #endif | |
19 | ||
20 | #include "math.h" | |
32c075e1 JJ |
21 | #include <math_private.h> |
22 | #include <float.h> | |
dfd2257a UD |
23 | |
24 | #ifdef __STDC__ | |
36fe9ac9 | 25 | float __nexttowardf(float x, long double y) |
dfd2257a | 26 | #else |
36fe9ac9 | 27 | float __nexttowardf(x,y) |
dfd2257a | 28 | float x; |
af6f3906 | 29 | long double y; |
dfd2257a UD |
30 | #endif |
31 | { | |
32 | int32_t hx,ix,iy; | |
33 | u_int32_t hy,ly,esy; | |
34 | ||
35 | GET_FLOAT_WORD(hx,x); | |
36 | GET_LDOUBLE_WORDS(esy,hy,ly,y); | |
37 | ix = hx&0x7fffffff; /* |x| */ | |
38 | iy = esy&0x7fff; /* |y| */ | |
39 | ||
636ccfc8 UD |
40 | if((ix>0x7f800000) || /* x is nan */ |
41 | (iy>=0x7fff&&((hy|ly)!=0))) /* y is nan */ | |
dfd2257a UD |
42 | return x+y; |
43 | if((long double) x==y) return y; /* x=y, return y */ | |
44 | if(ix==0) { /* x == 0 */ | |
32c075e1 | 45 | float u; |
636ccfc8 | 46 | SET_FLOAT_WORD(x,((esy&0x8000)<<16)|1);/* return +-minsub*/ |
32c075e1 JJ |
47 | u = math_opt_barrier (x); |
48 | u = u * u; | |
49 | math_force_eval (u); /* raise underflow flag */ | |
50 | return x; | |
dfd2257a UD |
51 | } |
52 | if(hx>=0) { /* x > 0 */ | |
abfbdde1 UD |
53 | if(esy>=0x8000||((ix>>23)&0xff)>iy-0x3f80 |
54 | || (((ix>>23)&0xff)==iy-0x3f80 | |
dfd2257a UD |
55 | && ((ix&0x7fffff)<<8)>(hy&0x7fffffff))) {/* x > y, x -= ulp */ |
56 | hx -= 1; | |
57 | } else { /* x < y, x += ulp */ | |
58 | hx += 1; | |
59 | } | |
60 | } else { /* x < 0 */ | |
abfbdde1 UD |
61 | if(esy<0x8000||((ix>>23)&0xff)>iy-0x3f80 |
62 | || (((ix>>23)&0xff)==iy-0x3f80 | |
dfd2257a UD |
63 | && ((ix&0x7fffff)<<8)>(hy&0x7fffffff))) {/* x < y, x -= ulp */ |
64 | hx -= 1; | |
65 | } else { /* x > y, x += ulp */ | |
66 | hx += 1; | |
67 | } | |
68 | } | |
69 | hy = hx&0x7f800000; | |
32c075e1 JJ |
70 | if(hy>=0x7f800000) { |
71 | x = x+x; /* overflow */ | |
72 | if (FLT_EVAL_METHOD != 0) | |
73 | /* Force conversion to float. */ | |
74 | asm ("" : "+m"(x)); | |
75 | return x; | |
76 | } | |
77 | if(hy<0x00800000) { | |
78 | float u = x*x; /* underflow */ | |
79 | math_force_eval (u); /* raise underflow flag */ | |
dfd2257a UD |
80 | } |
81 | SET_FLOAT_WORD(x,hx); | |
82 | return x; | |
83 | } | |
36fe9ac9 | 84 | weak_alias (__nexttowardf, nexttowardf) |