s_modff.c revision 302408
1157841Sflz/* s_modff.c -- float version of s_modf.c.
298186Sgordon * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
378344Sobrien */
4157473Sflz
578344Sobrien/*
678344Sobrien * ====================================================
778344Sobrien * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
878344Sobrien *
978344Sobrien * Developed at SunPro, a Sun Microsystems, Inc. business.
1078344Sobrien * Permission to use, copy, modify, and distribute this
1178344Sobrien * software is freely granted, provided that this notice
1278344Sobrien * is preserved.
1378344Sobrien * ====================================================
1478344Sobrien */
1578344Sobrien
1678344Sobrien#include <sys/cdefs.h>
1778344Sobrien__FBSDID("$FreeBSD: stable/11/lib/msun/src/s_modff.c 176451 2008-02-22 02:30:36Z das $");
1878344Sobrien
1978344Sobrien#include "math.h"
2078344Sobrien#include "math_private.h"
2178344Sobrien
2278344Sobrienstatic const float one = 1.0;
2378344Sobrien
2478344Sobrienfloat
2578344Sobrienmodff(float x, float *iptr)
2678344Sobrien{
2778344Sobrien	int32_t i0,j0;
2878344Sobrien	u_int32_t i;
2978344Sobrien	GET_FLOAT_WORD(i0,x);
3078344Sobrien	j0 = ((i0>>23)&0xff)-0x7f;	/* exponent of x */
3178344Sobrien	if(j0<23) {			/* integer part in x */
3278344Sobrien	    if(j0<0) {			/* |x|<1 */
3378344Sobrien	        SET_FLOAT_WORD(*iptr,i0&0x80000000);	/* *iptr = +-0 */
3478344Sobrien		return x;
3578344Sobrien	    } else {
3678344Sobrien		i = (0x007fffff)>>j0;
3778344Sobrien		if((i0&i)==0) {			/* x is integral */
3878344Sobrien		    u_int32_t ix;
3978344Sobrien		    *iptr = x;
4078344Sobrien		    GET_FLOAT_WORD(ix,x);
4178344Sobrien		    SET_FLOAT_WORD(x,ix&0x80000000);	/* return +-0 */
42157473Sflz		    return x;
43157473Sflz		} else {
4478344Sobrien		    SET_FLOAT_WORD(*iptr,i0&(~i));
4598186Sgordon		    return x - *iptr;
4698186Sgordon		}
4798186Sgordon	    }
48131550Scperciva	} else {			/* no fraction part */
49131550Scperciva	    u_int32_t ix;
50131550Scperciva	    *iptr = x*one;
51131550Scperciva	    if (x != x)			/* NaN */
5298186Sgordon		return x;
5398186Sgordon	    GET_FLOAT_WORD(ix,x);
5498186Sgordon	    SET_FLOAT_WORD(x,ix&0x80000000);	/* return +-0 */
55103018Sgordon	    return x;
56124832Smtm	}
57124832Smtm}
58161435Syar