]>
Commit | Line | Data |
---|---|---|
636ccfc8 UD |
1 | /* s_nexttowardf.c -- float version of s_nextafter.c. |
2 | * Special i387 version. | |
3 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. | |
4 | */ | |
5 | ||
6 | /* | |
7 | * ==================================================== | |
8 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | |
9 | * | |
10 | * Developed at SunPro, a Sun Microsystems, Inc. business. | |
11 | * Permission to use, copy, modify, and distribute this | |
12 | * software is freely granted, provided that this notice | |
13 | * is preserved. | |
14 | * ==================================================== | |
15 | */ | |
16 | ||
17 | #if defined(LIBM_SCCS) && !defined(lint) | |
18 | static char rcsid[] = "$NetBSD: $"; | |
19 | #endif | |
20 | ||
21 | #include "math.h" | |
32c075e1 JJ |
22 | #include <math_private.h> |
23 | #include <float.h> | |
636ccfc8 UD |
24 | |
25 | #ifdef __STDC__ | |
26 | float __nexttowardf(float x, long double y) | |
27 | #else | |
28 | float __nexttowardf(x,y) | |
29 | float x; | |
30 | long double y; | |
31 | #endif | |
32 | { | |
33 | int32_t hx,ix,iy; | |
34 | u_int32_t hy,ly,esy; | |
35 | ||
36 | GET_FLOAT_WORD(hx,x); | |
37 | GET_LDOUBLE_WORDS(esy,hy,ly,y); | |
38 | ix = hx&0x7fffffff; /* |x| */ | |
39 | iy = esy&0x7fff; /* |y| */ | |
40 | ||
41 | /* Intel's extended format has the normally implicit 1 explicit | |
42 | present. Sigh! */ | |
43 | if((ix>0x7f800000) || /* x is nan */ | |
44 | (iy>=0x7fff&&(((hy&0x7fffffff)|ly)!=0))) /* y is nan */ | |
45 | return x+y; | |
46 | if((long double) x==y) return y; /* x=y, return y */ | |
47 | if(ix==0) { /* x == 0 */ | |
32c075e1 | 48 | float u; |
636ccfc8 | 49 | SET_FLOAT_WORD(x,((esy&0x8000)<<16)|1);/* return +-minsub*/ |
32c075e1 JJ |
50 | u = math_opt_barrier (x); |
51 | u = u * u; | |
52 | math_force_eval (u); /* raise underflow flag */ | |
53 | return x; | |
636ccfc8 UD |
54 | } |
55 | if(hx>=0) { /* x > 0 */ | |
56 | if(esy>=0x8000||((ix>>23)&0xff)>iy-0x3f80 | |
57 | || (((ix>>23)&0xff)==iy-0x3f80 | |
58 | && ((ix&0x7fffff)<<8)>(hy&0x7fffffff))) {/* x > y, x -= ulp */ | |
59 | hx -= 1; | |
60 | } else { /* x < y, x += ulp */ | |
61 | hx += 1; | |
62 | } | |
63 | } else { /* x < 0 */ | |
64 | if(esy<0x8000||((ix>>23)&0xff)>iy-0x3f80 | |
65 | || (((ix>>23)&0xff)==iy-0x3f80 | |
66 | && ((ix&0x7fffff)<<8)>(hy&0x7fffffff))) {/* x < y, x -= ulp */ | |
67 | hx -= 1; | |
68 | } else { /* x > y, x += ulp */ | |
69 | hx += 1; | |
70 | } | |
71 | } | |
72 | hy = hx&0x7f800000; | |
07449987 UD |
73 | if(hy>=0x7f800000) { |
74 | x = x+x; /* overflow */ | |
32c075e1 JJ |
75 | if (FLT_EVAL_METHOD != 0) |
76 | /* Force conversion to float. */ | |
77 | asm ("" : "+m"(x)); | |
07449987 UD |
78 | return x; |
79 | } | |
32c075e1 JJ |
80 | if(hy<0x00800000) { |
81 | float u = x*x; /* underflow */ | |
82 | math_force_eval (u); /* raise underflow flag */ | |
636ccfc8 UD |
83 | } |
84 | SET_FLOAT_WORD(x,hx); | |
85 | return x; | |
86 | } | |
87 | weak_alias (__nexttowardf, nexttowardf) |