1 /* @(#)s_nextafter.c 5.1 93/09/24 */
2 /* $FreeBSD: head/lib/msun/src/s_nextafter.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
24 #include "math_private.h"
27 nextafter(double x, double y)
33 EXTRACT_WORDS(hx,lx,x);
34 EXTRACT_WORDS(hy,ly,y);
35 ix = hx&0x7fffffff; /* |x| */
36 iy = hy&0x7fffffff; /* |y| */
38 if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */
39 ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */
41 if(x==y) return y; /* x=y, return y */
42 if((ix|lx)==0) { /* x == 0 */
43 INSERT_WORDS(x,hy&0x80000000,1); /* return +-minsubnormal */
45 if(t==x) return t; else return x; /* raise underflow flag */
47 if(hx>=0) { /* x > 0 */
48 if(hx>hy||((hx==hy)&&(lx>ly))) { /* x > y, x -= ulp */
51 } else { /* x < y, x += ulp */
56 if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){/* x < y, x -= ulp */
59 } else { /* x > y, x += ulp */
65 if(hy>=0x7ff00000) return x+x; /* overflow */
66 if(hy<0x00100000) { /* underflow */
68 if(t!=x) { /* raise underflow flag */
69 INSERT_WORDS(y,hx,lx);
73 INSERT_WORDS(x,hx,lx);
77 #if (LDBL_MANT_DIG == 53)
78 __weak_reference(nextafter, nexttoward);
79 __weak_reference(nextafter, nexttowardl);
80 __weak_reference(nextafter, nextafterl);