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 * ====================================================
13 #include <sys/cdefs.h>
14 __FBSDID("$FreeBSD$");
18 * return the next machine floating-point number of x in the
27 #include "math_private.h"
29 #if LDBL_MAX_EXP != 0x4000
30 #error "Unsupported long double format"
34 nextafterl(long double x, long double y)
36 volatile long double t;
37 union IEEEl2bits ux, uy;
42 if ((ux.bits.exp == 0x7fff &&
43 ((ux.bits.manh&~LDBL_NBIT)|ux.bits.manl) != 0) ||
44 (uy.bits.exp == 0x7fff &&
45 ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl) != 0))
46 return x+y; /* x or y is nan */
47 if(x==y) return y; /* x=y, return y */
49 ux.bits.manh = 0; /* return +-minsubnormal */
51 ux.bits.sign = uy.bits.sign;
53 if(t==ux.e) return t; else return ux.e; /* raise underflow flag */
55 if(x>0.0 ^ x<y) { /* x -= ulp */
57 if ((ux.bits.manh&~LDBL_NBIT)==0)
59 ux.bits.manh = (ux.bits.manh - 1) | (ux.bits.manh & LDBL_NBIT);
62 } else { /* x += ulp */
65 ux.bits.manh = (ux.bits.manh + 1) | (ux.bits.manh & LDBL_NBIT);
66 if ((ux.bits.manh&~LDBL_NBIT)==0)
70 if(ux.bits.exp==0x7fff) return x+x; /* overflow */
71 if(ux.bits.exp==0) { /* underflow */
74 if(t!=ux.e) /* raise underflow flag */
80 __strong_reference(nextafterl, nexttowardl);