s_rintf.c revision 175480
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 175480 2008-01-19 16:37:57Z bde $";
182116Sjkh#endif
192116Sjkh
20175480Sbde#include <float.h>
21175480Sbde#include <stdint.h>
22175480Sbde
232116Sjkh#include "math.h"
242116Sjkh#include "math_private.h"
252116Sjkh
26130285Sdasstatic const float
272116SjkhTWO23[2]={
282116Sjkh  8.3886080000e+06, /* 0x4b000000 */
292116Sjkh -8.3886080000e+06, /* 0xcb000000 */
302116Sjkh};
312116Sjkh
3297413Salfredfloat
3397413Salfredrintf(float x)
342116Sjkh{
352116Sjkh	int32_t i0,j0,sx;
36175480Sbde	float w,t;
372116Sjkh	GET_FLOAT_WORD(i0,x);
382116Sjkh	sx = (i0>>31)&1;
392116Sjkh	j0 = ((i0>>23)&0xff)-0x7f;
402116Sjkh	if(j0<23) {
418870Srgrimes	    if(j0<0) {
422116Sjkh		if((i0&0x7fffffff)==0) return x;
43175480Sbde		STRICT_ASSIGN(float,w,TWO23[sx]+x);
442116Sjkh	        t =  w-TWO23[sx];
45153046Sbde		GET_FLOAT_WORD(i0,t);
46153046Sbde		SET_FLOAT_WORD(t,(i0&0x7fffffff)|(sx<<31));
472116Sjkh	        return t;
482116Sjkh	    }
49175480Sbde	    STRICT_ASSIGN(float,w,TWO23[sx]+x);
50130285Sdas	    return w-TWO23[sx];
512116Sjkh	}
52130285Sdas	if(j0==0x80) return x+x;	/* inf or NaN */
53130285Sdas	else return x;			/* x is integral */
542116Sjkh}
55