POK
|
00001 /* 00002 * POK header 00003 * 00004 * The following file is a part of the POK project. Any modification should 00005 * made according to the POK licence. You CANNOT use this file or a part of 00006 * this file is this part of a file for your own project 00007 * 00008 * For more information on the POK licence, please see our LICENCE FILE 00009 * 00010 * Please follow the coding guidelines described in doc/CODING_GUIDELINES 00011 * 00012 * Copyright (c) 2007-2009 POK team 00013 * 00014 * Created by julien on Fri Jan 30 14:41:34 2009 00015 */ 00016 00017 /* s_rintf.c -- float version of s_rint.c. 00018 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 00019 */ 00020 00021 /* 00022 * ==================================================== 00023 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 00024 * 00025 * Developed at SunPro, a Sun Microsystems, Inc. business. 00026 * Permission to use, copy, modify, and distribute this 00027 * software is freely granted, provided that this notice 00028 * is preserved. 00029 * ==================================================== 00030 */ 00031 00032 #ifdef POK_NEEDS_LIBMATH 00033 00034 #include <libm.h> 00035 #include "math_private.h" 00036 00037 static const float 00038 TWO23[2]={ 00039 8.3886080000e+06, /* 0x4b000000 */ 00040 -8.3886080000e+06, /* 0xcb000000 */ 00041 }; 00042 00043 float 00044 rintf(float x) 00045 { 00046 int32_t i0,jj0,sx; 00047 uint32_t i,i1; 00048 #ifdef __i386__ /* XXX gcc4 will omit the rounding otherwise */ 00049 volatile 00050 #endif 00051 float w; 00052 float t; 00053 GET_FLOAT_WORD(i0,x); 00054 sx = (i0>>31)&1; 00055 jj0 = ((i0>>23)&0xff)-0x7f; 00056 if(jj0<23) { 00057 if(jj0<0) { 00058 if((i0&0x7fffffff)==0) return x; 00059 i1 = (i0&0x07fffff); 00060 i0 &= 0xfff00000; 00061 i0 |= ((i1|-i1)>>9)&0x400000; 00062 SET_FLOAT_WORD(x,i0); 00063 w = TWO23[sx]+x; 00064 t = w-TWO23[sx]; 00065 GET_FLOAT_WORD(i0,t); 00066 SET_FLOAT_WORD(t,(i0&0x7fffffff)|(sx<<31)); 00067 return t; 00068 } else { 00069 i = (0x007fffff)>>jj0; 00070 if((i0&i)==0) return x; /* x is integral */ 00071 i>>=1; 00072 if((i0&i)!=0) i0 = (i0&(~i))|((0x100000)>>jj0); 00073 } 00074 } else { 00075 if(jj0==0x80) return x+x; /* inf or NaN */ 00076 else return x; /* x is integral */ 00077 } 00078 SET_FLOAT_WORD(x,i0); 00079 w = TWO23[sx]+x; 00080 return w-TWO23[sx]; 00081 } 00082 00083 #endif