]>
Commit | Line | Data |
---|---|---|
f7eac6eb RM |
1 | /* s_nextafterf.c -- float version of s_nextafter.c. |
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 | |
bc9f6000 | 11 | * software is freely granted, provided that this notice |
f7eac6eb RM |
12 | * is preserved. |
13 | * ==================================================== | |
14 | */ | |
15 | ||
16 | #if defined(LIBM_SCCS) && !defined(lint) | |
17 | static char rcsid[] = "$NetBSD: s_nextafterf.c,v 1.4 1995/05/10 20:48:01 jtc Exp $"; | |
18 | #endif | |
19 | ||
20 | #include "math.h" | |
a334319f | 21 | #include "math_private.h" |
64b02fd2 | 22 | #include <float.h> |
f7eac6eb RM |
23 | |
24 | #ifdef __STDC__ | |
25 | float __nextafterf(float x, float y) | |
26 | #else | |
27 | float __nextafterf(x,y) | |
28 | float x,y; | |
29 | #endif | |
30 | { | |
31 | int32_t hx,hy,ix,iy; | |
32 | ||
33 | GET_FLOAT_WORD(hx,x); | |
34 | GET_FLOAT_WORD(hy,y); | |
35 | ix = hx&0x7fffffff; /* |x| */ | |
36 | iy = hy&0x7fffffff; /* |y| */ | |
37 | ||
bc9f6000 UD |
38 | if((ix>0x7f800000) || /* x is nan */ |
39 | (iy>0x7f800000)) /* y is nan */ | |
40 | return x+y; | |
41 | if(x==y) return y; /* x=y, return y */ | |
f7eac6eb RM |
42 | if(ix==0) { /* x == 0 */ |
43 | SET_FLOAT_WORD(x,(hy&0x80000000)|1);/* return +-minsubnormal */ | |
a334319f UD |
44 | y = x*x; |
45 | if(y==x) return y; else return x; /* raise underflow flag */ | |
bc9f6000 | 46 | } |
f7eac6eb RM |
47 | if(hx>=0) { /* x > 0 */ |
48 | if(hx>hy) { /* x > y, x -= ulp */ | |
49 | hx -= 1; | |
50 | } else { /* x < y, x += ulp */ | |
51 | hx += 1; | |
52 | } | |
53 | } else { /* x < 0 */ | |
54 | if(hy>=0||hx>hy){ /* x < y, x -= ulp */ | |
55 | hx -= 1; | |
56 | } else { /* x > y, x += ulp */ | |
57 | hx += 1; | |
58 | } | |
59 | } | |
60 | hy = hx&0x7f800000; | |
64b02fd2 | 61 | if(hy>=0x7f800000) { |
07449987 UD |
62 | x = x+x; /* overflow */ |
63 | if (FLT_EVAL_METHOD != 0) | |
a334319f | 64 | asm ("" : "=m"(x) : "m"(x)); |
07449987 | 65 | return x; /* overflow */ |
64b02fd2 | 66 | } |
a334319f UD |
67 | if(hy<0x00800000) { /* underflow */ |
68 | y = x*x; | |
69 | if(y!=x) { /* raise underflow flag */ | |
70 | SET_FLOAT_WORD(y,hx); | |
71 | return y; | |
72 | } | |
f7eac6eb RM |
73 | } |
74 | SET_FLOAT_WORD(x,hx); | |
75 | return x; | |
76 | } | |
77 | weak_alias (__nextafterf, nextafterf) |