1 /* @(#)s_nextafter.c 5.1 93/09/24 */
2 /* $FreeBSD: head/lib/msun/src/s_nextafterl.c 176451 2008-02-22 02:30:36Z das $ */
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
11 * ====================================================
16 * return the next machine floating-point number of x in the
25 #include "math_private.h"
27 #if LDBL_MAX_EXP != 0x4000
28 #error "Unsupported long double format"
32 nextafterl(long double x, long double y)
34 volatile long double t;
35 union IEEEl2bits ux, uy;
40 if ((ux.bits.exp == 0x7fff &&
41 ((ux.bits.manh&~LDBL_NBIT)|ux.bits.manl) != 0) ||
42 (uy.bits.exp == 0x7fff &&
43 ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl) != 0))
44 return x+y; /* x or y is nan */
45 if(x==y) return y; /* x=y, return y */
47 ux.bits.manh = 0; /* return +-minsubnormal */
49 ux.bits.sign = uy.bits.sign;
51 if(t==ux.e) return t; else return ux.e; /* raise underflow flag */
53 if(x>0.0 ^ x<y) { /* x -= ulp */
55 if ((ux.bits.manh&~LDBL_NBIT)==0)
57 ux.bits.manh = (ux.bits.manh - 1) | (ux.bits.manh & LDBL_NBIT);
60 } else { /* x += ulp */
63 ux.bits.manh = (ux.bits.manh + 1) | (ux.bits.manh & LDBL_NBIT);
64 if ((ux.bits.manh&~LDBL_NBIT)==0)
68 if(ux.bits.exp==0x7fff) return x+x; /* overflow */
69 if(ux.bits.exp==0) { /* underflow */
72 if(t!=ux.e) /* raise underflow flag */
78 __strong_reference(nextafterl, nexttowardl);