GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libm/src/s_nextafterf.c Lines: 20 31 64.5 %
Date: 2017-11-07 Branches: 10 22 45.5 %

Line Branch Exec Source
1
/* s_nextafterf.c -- float version of s_nextafter.c.
2
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3
 */
4
5
/*
6
 * ====================================================
7
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8
 *
9
 * Developed at SunPro, a Sun Microsystems, Inc. business.
10
 * Permission to use, copy, modify, and distribute this
11
 * software is freely granted, provided that this notice
12
 * is preserved.
13
 * ====================================================
14
 */
15
16
#include "math.h"
17
#include "math_private.h"
18
19
float
20
nextafterf(float x, float y)
21
{
22
	int32_t hx,hy,ix,iy;
23
24
90
	GET_FLOAT_WORD(hx,x);
25
45
	GET_FLOAT_WORD(hy,y);
26
45
	ix = hx&0x7fffffff;		/* |x| */
27
45
	iy = hy&0x7fffffff;		/* |y| */
28
29
90
	if((ix>0x7f800000) ||   /* x is nan */
30
45
	   (iy>0x7f800000))     /* y is nan */
31
15
	   return x+y;
32
50
	if(x==y) return y;		/* x=y, return y */
33
10
	if(ix==0) {				/* x == 0 */
34
	    SET_FLOAT_WORD(x,(hy&0x80000000)|1);/* return +-minsubnormal */
35
	    y = x*x;
36
	    if(y==x) return y; else return x;	/* raise underflow flag */
37
	}
38
10
	if(hx>=0) {				/* x > 0 */
39
10
	    if(hx>hy) {				/* x > y, x -= ulp */
40
5
		hx -= 1;
41
5
	    } else {				/* x < y, x += ulp */
42
5
		hx += 1;
43
	    }
44
	} else {				/* x < 0 */
45
	    if(hy>=0||hx>hy){			/* x < y, x -= ulp */
46
		hx -= 1;
47
	    } else {				/* x > y, x += ulp */
48
		hx += 1;
49
	    }
50
	}
51
10
	hy = hx&0x7f800000;
52
10
	if(hy>=0x7f800000) return x+x;	/* overflow  */
53
10
	if(hy<0x00800000) {		/* underflow */
54
	    y = x*x;
55
	    if(y!=x) {		/* raise underflow flag */
56
	        SET_FLOAT_WORD(y,hx);
57
		return y;
58
	    }
59
	}
60
10
	SET_FLOAT_WORD(x,hx);
61
10
	return x;
62
45
}