Branch data Line data Source code
1 : : /* @(#)s_nextafter.c 5.1 93/09/24 */
2 : : /*
3 : : * ====================================================
4 : : * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 : : *
6 : : * Developed at SunPro, a Sun Microsystems, Inc. business.
7 : : * Permission to use, copy, modify, and distribute this
8 : : * software is freely granted, provided that this notice
9 : : * is preserved.
10 : : * ====================================================
11 : : */
12 : :
13 : : #include "cdefs-compat.h"
14 : : //__FBSDID("$FreeBSD: src/lib/msun/src/s_nextafterl.c,v 1.2 2008/02/22 02:30:36 das Exp $");
15 : :
16 : : /* IEEE functions
17 : : * nextafter(x,y)
18 : : * return the next machine floating-point number of x in the
19 : : * direction toward y.
20 : : * Special cases:
21 : : */
22 : :
23 : : #include <float.h>
24 : : #include <openlibm_math.h>
25 : :
26 : : #include "fpmath.h"
27 : : #include "math_private.h"
28 : :
29 : : #if LDBL_MAX_EXP != 0x4000
30 : : #error "Unsupported long double format"
31 : : #endif
32 : :
33 : : OLM_DLLEXPORT long double
34 : 0 : nextafterl(long double x, long double y)
35 : : {
36 : : volatile long double t;
37 : : union IEEEl2bits ux, uy;
38 : :
39 : 0 : ux.e = x;
40 : 0 : uy.e = y;
41 : :
42 [ # # ]: 0 : if ((ux.bits.exp == 0x7fff &&
43 [ # # ]: 0 : ((ux.bits.manh&~LDBL_NBIT)|ux.bits.manl) != 0) ||
44 [ # # ]: 0 : (uy.bits.exp == 0x7fff &&
45 [ # # ]: 0 : ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl) != 0))
46 : 0 : return x+y; /* x or y is nan */
47 [ # # ]: 0 : if(x==y) return y; /* x=y, return y */
48 [ # # ]: 0 : if(x==0.0) {
49 : 0 : ux.bits.manh = 0; /* return +-minsubnormal */
50 : 0 : ux.bits.manl = 1;
51 : 0 : ux.bits.sign = uy.bits.sign;
52 : 0 : t = ux.e*ux.e;
53 [ # # ]: 0 : if(t==ux.e) return t; else return ux.e; /* raise underflow flag */
54 : : }
55 [ # # ]: 0 : if((x>0.0) ^ (x<y)) { /* x -= ulp */
56 [ # # ]: 0 : if(ux.bits.manl==0) {
57 [ # # ]: 0 : if ((ux.bits.manh&~LDBL_NBIT)==0)
58 : 0 : ux.bits.exp -= 1;
59 : 0 : ux.bits.manh = (ux.bits.manh - 1) | (ux.bits.manh & LDBL_NBIT);
60 : : }
61 : 0 : ux.bits.manl -= 1;
62 : : } else { /* x += ulp */
63 : 0 : ux.bits.manl += 1;
64 [ # # ]: 0 : if(ux.bits.manl==0) {
65 : 0 : ux.bits.manh = (ux.bits.manh + 1) | (ux.bits.manh & LDBL_NBIT);
66 [ # # ]: 0 : if ((ux.bits.manh&~LDBL_NBIT)==0)
67 : 0 : ux.bits.exp += 1;
68 : : }
69 : : }
70 [ # # ]: 0 : if(ux.bits.exp==0x7fff) return x+x; /* overflow */
71 [ # # ]: 0 : if(ux.bits.exp==0) { /* underflow */
72 : 0 : mask_nbit_l(ux);
73 : 0 : t = ux.e * ux.e;
74 [ # # ]: 0 : if(t!=ux.e) /* raise underflow flag */
75 : 0 : return ux.e;
76 : : }
77 : 0 : return ux.e;
78 : : }
79 : :
80 : : openlibm_strong_reference(nextafterl, nexttowardl);
|