s_rintf.c revision 8870
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 178870Srgrimesstatic char rcsid[] = "$Id: s_rintf.c,v 1.1.1.1 1994/08/19 09:39:58 jkh Exp $"; 182116Sjkh#endif 192116Sjkh 202116Sjkh#include "math.h" 212116Sjkh#include "math_private.h" 222116Sjkh 232116Sjkh#ifdef __STDC__ 242116Sjkhstatic const float 252116Sjkh#else 268870Srgrimesstatic float 272116Sjkh#endif 282116SjkhTWO23[2]={ 292116Sjkh 8.3886080000e+06, /* 0x4b000000 */ 302116Sjkh -8.3886080000e+06, /* 0xcb000000 */ 312116Sjkh}; 322116Sjkh 332116Sjkh#ifdef __STDC__ 342116Sjkh float rintf(float x) 352116Sjkh#else 362116Sjkh float rintf(x) 372116Sjkh float x; 382116Sjkh#endif 392116Sjkh{ 402116Sjkh int32_t i0,j0,sx; 412116Sjkh u_int32_t i,i1; 422116Sjkh float w,t; 432116Sjkh GET_FLOAT_WORD(i0,x); 442116Sjkh sx = (i0>>31)&1; 452116Sjkh j0 = ((i0>>23)&0xff)-0x7f; 462116Sjkh if(j0<23) { 478870Srgrimes if(j0<0) { 482116Sjkh if((i0&0x7fffffff)==0) return x; 492116Sjkh i1 = (i0&0x07fffff); 502116Sjkh i0 &= 0xfff00000; 512116Sjkh i0 |= ((i1|-i1)>>9)&0x400000; 522116Sjkh SET_FLOAT_WORD(x,i0); 532116Sjkh w = TWO23[sx]+x; 542116Sjkh t = w-TWO23[sx]; 552116Sjkh GET_FLOAT_WORD(i0,t); 562116Sjkh SET_FLOAT_WORD(t,(i0&0x7fffffff)|(sx<<31)); 572116Sjkh return t; 582116Sjkh } else { 592116Sjkh i = (0x007fffff)>>j0; 602116Sjkh if((i0&i)==0) return x; /* x is integral */ 612116Sjkh i>>=1; 622116Sjkh if((i0&i)!=0) i0 = (i0&(~i))|((0x100000)>>j0); 632116Sjkh } 642116Sjkh } else { 652116Sjkh if(j0==0x80) return x+x; /* inf or NaN */ 662116Sjkh else return x; /* x is integral */ 672116Sjkh } 682116Sjkh SET_FLOAT_WORD(x,i0); 692116Sjkh w = TWO23[sx]+x; 702116Sjkh return w-TWO23[sx]; 712116Sjkh} 72