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
16176451Sdas#include <sys/cdefs.h>
17176451Sdas__FBSDID("$FreeBSD$");
182116Sjkh
19175480Sbde#include <float.h>
20175480Sbde#include <stdint.h>
21175480Sbde
222116Sjkh#include "math.h"
232116Sjkh#include "math_private.h"
242116Sjkh
25130285Sdasstatic const float
262116SjkhTWO23[2]={
272116Sjkh  8.3886080000e+06, /* 0x4b000000 */
282116Sjkh -8.3886080000e+06, /* 0xcb000000 */
292116Sjkh};
302116Sjkh
3197413Salfredfloat
3297413Salfredrintf(float x)
332116Sjkh{
342116Sjkh	int32_t i0,j0,sx;
35175480Sbde	float w,t;
362116Sjkh	GET_FLOAT_WORD(i0,x);
372116Sjkh	sx = (i0>>31)&1;
382116Sjkh	j0 = ((i0>>23)&0xff)-0x7f;
392116Sjkh	if(j0<23) {
408870Srgrimes	    if(j0<0) {
412116Sjkh		if((i0&0x7fffffff)==0) return x;
42175480Sbde		STRICT_ASSIGN(float,w,TWO23[sx]+x);
432116Sjkh	        t =  w-TWO23[sx];
44153046Sbde		GET_FLOAT_WORD(i0,t);
45153046Sbde		SET_FLOAT_WORD(t,(i0&0x7fffffff)|(sx<<31));
462116Sjkh	        return t;
472116Sjkh	    }
48175480Sbde	    STRICT_ASSIGN(float,w,TWO23[sx]+x);
49130285Sdas	    return w-TWO23[sx];
502116Sjkh	}
51130285Sdas	if(j0==0x80) return x+x;	/* inf or NaN */
52130285Sdas	else return x;			/* x is integral */
532116Sjkh}
54