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_modf.c 5.1 93/09/24 */ 00018 /* 00019 * ==================================================== 00020 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 00021 * 00022 * Developed at SunPro, a Sun Microsystems, Inc. business. 00023 * Permission to use, copy, modify, and distribute this 00024 * software is freely granted, provided that this notice 00025 * is preserved. 00026 * ==================================================== 00027 */ 00028 00029 /* 00030 * modf(double x, double *iptr) 00031 * return fraction part of x, and return x's integral part in *iptr. 00032 * Method: 00033 * Bit twiddling. 00034 * 00035 * Exception: 00036 * No exception. 00037 */ 00038 00039 #ifdef POK_NEEDS_LIBMATH 00040 00041 #include <libm.h> 00042 #include "math_private.h" 00043 00044 static const double one = 1.0; 00045 00046 double 00047 modf(double x, double *iptr) 00048 { 00049 int32_t i0,i1,jj0; 00050 uint32_t i; 00051 EXTRACT_WORDS(i0,i1,x); 00052 jj0 = (((uint32_t)i0>>20)&0x7ff)-0x3ff; /* exponent of x */ 00053 if(jj0<20) { /* integer part in high x */ 00054 if(jj0<0) { /* |x|<1 */ 00055 INSERT_WORDS(*iptr,i0&0x80000000,0); /* *iptr = +-0 */ 00056 return x; 00057 } else { 00058 i = (0x000fffff)>>jj0; 00059 if(((i0&i)|i1)==0) { /* x is integral */ 00060 uint32_t high; 00061 *iptr = x; 00062 GET_HIGH_WORD(high,x); 00063 INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */ 00064 return x; 00065 } else { 00066 INSERT_WORDS(*iptr,i0&(~i),0); 00067 return x - *iptr; 00068 } 00069 } 00070 } else if (jj0>51) { /* no fraction part */ 00071 uint32_t high; 00072 *iptr = x*one; 00073 GET_HIGH_WORD(high,x); 00074 INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */ 00075 return x; 00076 } else { /* fraction part in low x */ 00077 i = ((uint32_t)(0xffffffff))>>(jj0-20); 00078 if((i1&i)==0) { /* x is integral */ 00079 uint32_t high; 00080 *iptr = x; 00081 GET_HIGH_WORD(high,x); 00082 INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */ 00083 return x; 00084 } else { 00085 INSERT_WORDS(*iptr,i0,i1&(~i)); 00086 return x - *iptr; 00087 } 00088 } 00089 } 00090 00091 #endif