00001 #if !defined(__ppc__)
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 #if defined(LIBM_SCCS) && !defined(lint)
00015 static char rcsid[] = "$NetBSD: s_floor.c,v 1.8 1995/05/10 20:47:20 jtc Exp $";
00016 #endif
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 #include "math.h"
00028 #include "mathP.h"
00029 
00030 #ifdef __STDC__
00031 static const double huge = 1.0e300;
00032 #else
00033 static double huge = 1.0e300;
00034 #endif
00035 
00036 #ifdef __STDC__
00037     double floor(double x)
00038 #else
00039     double floor(x)
00040     double x;
00041 #endif
00042 {
00043     int32_t i0,i1,j0;
00044     u_int32_t i,j;
00045     EXTRACT_WORDS(i0,i1,x);
00046     j0 = ((i0>>20)&0x7ff)-0x3ff;
00047     if(j0<20) {
00048         if(j0<0) {  
00049         if(huge+x>0.0) {
00050             if(i0>=0) {i0=i1=0;} 
00051             else if(((i0&0x7fffffff)|i1)!=0)
00052             { i0=0xbff00000;i1=0;}
00053         }
00054         } else {
00055         i = (0x000fffff)>>j0;
00056         if(((i0&i)|i1)==0) return x; 
00057         if(huge+x>0.0) {    
00058             if(i0<0) i0 += (0x00100000)>>j0;
00059             i0 &= (~i); i1=0;
00060         }
00061         }
00062     } else if (j0>51) {
00063         if(j0==0x400) return x+x;   
00064         else return x;      
00065     } else {
00066         i = ((u_int32_t)(0xffffffff))>>(j0-20);
00067         if((i1&i)==0) return x; 
00068         if(huge+x>0.0) {        
00069         if(i0<0) {
00070             if(j0==20) i0+=1; 
00071             else {
00072             j = i1+(1<<(52-j0));
00073             if(j<i1) i0 +=1 ;   
00074             i1=j;
00075             }
00076         }
00077         i1 &= (~i);
00078         }
00079     }
00080     INSERT_WORDS(x,i0,i1);
00081     return x;
00082 }
00083 #endif