Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1882 clevermous 1
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
2
/* s_nextafterf.c -- float version of s_nextafter.c.
3
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
4
 */
5
 
6
/*
7
 * ====================================================
8
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9
 *
10
 * Developed at SunPro, a Sun Microsystems, Inc. business.
11
 * Permission to use, copy, modify, and distribute this
12
 * software is freely granted, provided that this notice
13
 * is preserved.
14
 * ====================================================
15
 */
16
 
17
#if defined(LIBM_SCCS) && !defined(lint)
18
static char rcsid[] = "$Id: s_nextafterf.c,v 1.2 1994/08/18 23:07:15 jtc Exp $";
19
#endif
20
 
21
#include "math.h"
22
#include "math_private.h"
23
 
24
#ifdef __STDC__
25
	float nextafterf(float x, float y)
26
#else
27
	float nextafterf(x,y)
28
	float x,y;
29
#endif
30
{
31
	int32_t hx,hy,ix,iy;
32
 
33
	GET_FLOAT_WORD(hx,x);
34
	GET_FLOAT_WORD(hy,y);
35
	ix = hx&0x7fffffff;		/* |x| */
36
	iy = hy&0x7fffffff;		/* |y| */
37
 
38
	if((ix>0x7f800000) ||   /* x is nan */
39
	   (iy>0x7f800000))     /* y is nan */
40
	   return x+y;
41
	if(x==y) return x;		/* x=y, return x */
42
	if(ix==0) {				/* x == 0 */
43
	    SET_FLOAT_WORD(x,(hy&0x80000000)|1);/* return +-minsubnormal */
44
	    y = x*x;
45
	    if(y==x) return y; else return x;	/* raise underflow flag */
46
	}
47
	if(hx>=0) {				/* x > 0 */
48
	    if(hx>hy) {				/* x > y, x -= ulp */
49
		hx -= 1;
50
	    } else {				/* x < y, x += ulp */
51
		hx += 1;
52
	    }
53
	} else {				/* x < 0 */
54
	    if(hy>=0||hx>hy){			/* x < y, x -= ulp */
55
		hx -= 1;
56
	    } else {				/* x > y, x += ulp */
57
		hx += 1;
58
	    }
59
	}
60
	hy = hx&0x7f800000;
61
	if(hy>=0x7f800000) return x+x;	/* overflow  */
62
	if(hy<0x00800000) {		/* underflow */
63
	    y = x*x;
64
	    if(y!=x) {		/* raise underflow flag */
65
	        SET_FLOAT_WORD(y,hx);
66
		return y;
67
	    }
68
	}
69
	SET_FLOAT_WORD(x,hx);
70
	return x;
71
}