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
26 #include "math_private.h"
29 nextafter(double x, double y)
35 EXTRACT_WORDS(hx,lx,x);
36 EXTRACT_WORDS(hy,ly,y);
37 ix = hx&0x7fffffff; /* |x| */
38 iy = hy&0x7fffffff; /* |y| */
40 if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */
41 ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */
43 if(x==y) return y; /* x=y, return y */
44 if((ix|lx)==0) { /* x == 0 */
45 INSERT_WORDS(x,hy&0x80000000,1); /* return +-minsubnormal */
47 if(t==x) return t; else return x; /* raise underflow flag */
49 if(hx>=0) { /* x > 0 */
50 if(hx>hy||((hx==hy)&&(lx>ly))) { /* x > y, x -= ulp */
53 } else { /* x < y, x += ulp */
58 if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){/* x < y, x -= ulp */
61 } else { /* x > y, x += ulp */
67 if(hy>=0x7ff00000) return x+x; /* overflow */
68 if(hy<0x00100000) { /* underflow */
70 if(t!=x) { /* raise underflow flag */
71 INSERT_WORDS(y,hx,lx);
75 INSERT_WORDS(x,hx,lx);
79 #if (LDBL_MANT_DIG == 53)
80 __weak_reference(nextafter, nexttoward);
81 __weak_reference(nextafter, nexttowardl);
82 __weak_reference(nextafter, nextafterl);