1 /* @(#)s_nextafter.c 5.1 93/09/24 */
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
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
10 * ====================================================
14 static char rcsid
[] = "$FreeBSD: src/lib/msun/src/s_nextafterl.c,v 1.1 2005/03/07 04:56:46 das Exp $";
19 * return the next machine floating-point number of x in the
24 #include <sys/cdefs.h>
29 #include "math_private.h"
31 #if LDBL_MAX_EXP != 0x4000
32 #error "Unsupported long double format"
36 nextafterl(long double x
, long double y
)
38 volatile long double t
;
39 union IEEEl2bits ux
, uy
;
44 if ((ux
.bits
.exp
== 0x7fff &&
45 ((ux
.bits
.manh
&~LDBL_NBIT
)|ux
.bits
.manl
) != 0) ||
46 (uy
.bits
.exp
== 0x7fff &&
47 ((uy
.bits
.manh
&~LDBL_NBIT
)|uy
.bits
.manl
) != 0))
48 return x
+y
; /* x or y is nan */
49 if(x
==y
) return y
; /* x=y, return y */
51 ux
.bits
.manh
= 0; /* return +-minsubnormal */
53 ux
.bits
.sign
= uy
.bits
.sign
;
55 if(t
==ux
.e
) return t
; else return ux
.e
; /* raise underflow flag */
57 if(x
>0.0 ^ x
<y
) { /* x -= ulp */
59 if ((ux
.bits
.manh
&~LDBL_NBIT
)==0)
61 ux
.bits
.manh
= (ux
.bits
.manh
- 1) | (ux
.bits
.manh
& LDBL_NBIT
);
64 } else { /* x += ulp */
67 ux
.bits
.manh
= (ux
.bits
.manh
+ 1) | (ux
.bits
.manh
& LDBL_NBIT
);
68 if ((ux
.bits
.manh
&~LDBL_NBIT
)==0)
72 if(ux
.bits
.exp
==0x7fff) return x
+x
; /* overflow */
73 if(ux
.bits
.exp
==0) { /* underflow */
76 if(t
!=ux
.e
) /* raise underflow flag */
82 __strong_reference(nextafterl
, nexttowardl
);