1 /* s_modff.c -- float version of s_modf.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 <sys/cdefs.h>
17 #if defined(LIBM_SCCS) && !defined(lint)
18 __RCSID("$MirOS: src/lib/libm/src/s_modff.c,v 1.3 2011/10/18 19:46:29 bsiegert Exp $");
19 __RCSID("$NetBSD: s_modff.c,v 1.9 2010/01/27 14:07:41 drochner Exp $");
20 #endif
21 
22 #include "math.h"
23 #include "math_private.h"
24 
25 static const float one = 1.0;
26 
27 float
modff(float x,float * iptr)28 modff(float x, float *iptr)
29 {
30 	int32_t i0,jj0;
31 	u_int32_t i;
32 	GET_FLOAT_WORD(i0,x);
33 	jj0 = ((i0>>23)&0xff)-0x7f;	/* exponent of x */
34 	if(jj0<23) {			/* integer part in x */
35 	    if(jj0<0) {			/* |x|<1 */
36 	        SET_FLOAT_WORD(*iptr,i0&0x80000000);	/* *iptr = +-0 */
37 		return x;
38 	    } else {
39 		i = (0x007fffff)>>jj0;
40 		if((i0&i)==0) {			/* x is integral */
41 		    u_int32_t ix;
42 		    *iptr = x;
43 		    GET_FLOAT_WORD(ix,x);
44 		    SET_FLOAT_WORD(x,ix&0x80000000);	/* return +-0 */
45 		    return x;
46 		} else {
47 		    SET_FLOAT_WORD(*iptr,i0&(~i));
48 		    return x - *iptr;
49 		}
50 	    }
51 	} else {			/* no fraction part */
52 	    u_int32_t ix;
53 	    *iptr = x*one;
54 	    if (jj0 == 0x80)		/* +-inf or NaN */
55 		return 0.0 / x;		/* +-0 or NaN */
56 	    GET_FLOAT_WORD(ix,x);
57 	    SET_FLOAT_WORD(x,ix&0x80000000);	/* return +-0 */
58 	    return x;
59 	}
60 }
61