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_nexttoward.c,v 1.1 2005/03/07 04:56:46 das Exp $";
18 * We assume that a long double has a 15-bit exponent. On systems
19 * where long double is the same as double, nexttoward() is an alias
20 * for nextafter(), so we don't use this routine.
27 #include "math_private.h"
29 #if LDBL_MAX_EXP != 0x4000
30 #error "Unsupported long double format"
34 nexttoward(double x
, long double y
)
41 EXTRACT_WORDS(hx
,lx
,x
);
42 ix
= hx
&0x7fffffff; /* |x| */
45 if(((ix
>=0x7ff00000)&&((ix
-0x7ff00000)|lx
)!=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 (double)y
; /* x=y, return y */
51 INSERT_WORDS(x
,uy
.bits
.sign
<<31,1); /* return +-minsubnormal */
53 if(t
==x
) return t
; else return x
; /* raise underflow flag */
55 if(hx
>0.0 ^ x
< y
) { /* x -= ulp */
58 } else { /* x += ulp */
63 if(ix
>=0x7ff00000) return x
+x
; /* overflow */
64 if(ix
<0x00100000) { /* underflow */
66 if(t
!=x
) { /* raise underflow flag */
67 INSERT_WORDS(y
,hx
,lx
);
71 INSERT_WORDS(x
,hx
,lx
);