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_cbrtf.c -- float version of s_cbrt.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 <types.h> 00035 #include <libm.h> 00036 #include "math_private.h" 00037 00038 /* cbrtf(x) 00039 * Return cube root of x 00040 */ 00041 static const unsigned 00042 B1 = 709958130, /* B1 = (84+2/3-0.03306235651)*2**23 */ 00043 B2 = 642849266; /* B2 = (76+2/3-0.03306235651)*2**23 */ 00044 00045 static const float 00046 C = 5.4285717010e-01, /* 19/35 = 0x3f0af8b0 */ 00047 D = -7.0530611277e-01, /* -864/1225 = 0xbf348ef1 */ 00048 E = 1.4142856598e+00, /* 99/70 = 0x3fb50750 */ 00049 F = 1.6071428061e+00, /* 45/28 = 0x3fcdb6db */ 00050 G = 3.5714286566e-01; /* 5/14 = 0x3eb6db6e */ 00051 00052 float 00053 cbrtf(float x) 00054 { 00055 float r,s,t; 00056 int32_t hx; 00057 uint32_t sign; 00058 uint32_t high; 00059 00060 GET_FLOAT_WORD(hx,x); 00061 sign=hx&0x80000000; /* sign= sign(x) */ 00062 hx ^=sign; 00063 if(hx>=0x7f800000) return(x+x); /* cbrt(NaN,INF) is itself */ 00064 if(hx==0) 00065 return(x); /* cbrt(0) is itself */ 00066 00067 SET_FLOAT_WORD(x,hx); /* x <- |x| */ 00068 /* rough cbrt to 5 bits */ 00069 if(hx<0x00800000) /* subnormal number */ 00070 {SET_FLOAT_WORD(t,0x4b800000); /* set t= 2**24 */ 00071 t*=x; GET_FLOAT_WORD(high,t); SET_FLOAT_WORD(t,high/3+B2); 00072 } 00073 else 00074 SET_FLOAT_WORD(t,hx/3+B1); 00075 00076 00077 /* new cbrt to 23 bits */ 00078 r=t*t/x; 00079 s=C+r*t; 00080 t*=G+F/(s+E+D/s); 00081 00082 /* retore the sign bit */ 00083 GET_FLOAT_WORD(high,t); 00084 SET_FLOAT_WORD(t,high|sign); 00085 return(t); 00086 } 00087 00088 #endif 00089