s_rintf.c revision 153046
12116Sjkh/* s_rintf.c -- float version of s_rint.c.
22116Sjkh * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
32116Sjkh */
42116Sjkh
52116Sjkh/*
62116Sjkh * ====================================================
72116Sjkh * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
82116Sjkh *
92116Sjkh * Developed at SunPro, a Sun Microsystems, Inc. business.
102116Sjkh * Permission to use, copy, modify, and distribute this
118870Srgrimes * software is freely granted, provided that this notice
122116Sjkh * is preserved.
132116Sjkh * ====================================================
142116Sjkh */
152116Sjkh
162116Sjkh#ifndef lint
1750476Speterstatic char rcsid[] = "$FreeBSD: head/lib/msun/src/s_rintf.c 153046 2005-12-03 09:00:29Z bde $";
182116Sjkh#endif
192116Sjkh
20130285Sdas#include <sys/types.h>
212116Sjkh#include "math.h"
222116Sjkh#include "math_private.h"
232116Sjkh
24130285Sdasstatic const float
252116SjkhTWO23[2]={
262116Sjkh  8.3886080000e+06, /* 0x4b000000 */
272116Sjkh -8.3886080000e+06, /* 0xcb000000 */
282116Sjkh};
292116Sjkh
3097413Salfredfloat
3197413Salfredrintf(float x)
322116Sjkh{
332116Sjkh	int32_t i0,j0,sx;
34130285Sdas	volatile float w,t;	/* volatile works around gcc bug */
352116Sjkh	GET_FLOAT_WORD(i0,x);
362116Sjkh	sx = (i0>>31)&1;
372116Sjkh	j0 = ((i0>>23)&0xff)-0x7f;
382116Sjkh	if(j0<23) {
398870Srgrimes	    if(j0<0) {
402116Sjkh		if((i0&0x7fffffff)==0) return x;
412116Sjkh	        w = TWO23[sx]+x;
422116Sjkh	        t =  w-TWO23[sx];
43153046Sbde		GET_FLOAT_WORD(i0,t);
44153046Sbde		SET_FLOAT_WORD(t,(i0&0x7fffffff)|(sx<<31));
452116Sjkh	        return t;
462116Sjkh	    }
47130285Sdas	    w = TWO23[sx]+x;
48130285Sdas	    return w-TWO23[sx];
492116Sjkh	}
50130285Sdas	if(j0==0x80) return x+x;	/* inf or NaN */
51130285Sdas	else return x;			/* x is integral */
522116Sjkh}
53