www.pudn.com > EZW_.rar > GLOBAL.C


/*---------------------------------------------------------------------------*/ 
/*---------------------------------------------------------------------------*/ 
/*  
 * Mow-Song, Ng 2/9/2002 
 * msng@mmu.edu.my 
 * http://www.pesona.mmu.edu.my/~msng 
 * 
 * I do not claim copyright to the code, but if you use them or modify them, 
 * please drop me a mail. 
 * 
 */ 
/*---------------------------------------------------------------------------*/ 
/*---------------------------------------------------------------------------*/ 
 
#include "global.h" 
 
/*---------------------------------------------------------------------------*/ 
/*---------------------------------------------------------------------------*/ 
Real MOD (Real x, Real N) 
{ 
   Real xmodN = x - N*((int)(x/N)); 
   if (xmodN < 0) xmodN += N; 
   return xmodN; 
} 
 
 
/*---------------------------------------------------------------------------*/ 
/*---------------------------------------------------------------------------*/ 
Real square (Real x) 
{ 
	return (x*x);  
} 
 
/*---------------------------------------------------------------------------*/ 
/*---------------------------------------------------------------------------*/ 
int isquare (int x) 
{  
	return (x*x);  
} 
 
/*---------------------------------------------------------------------------*/ 
/*---------------------------------------------------------------------------*/ 
int sign(Real x)    
{  
	return (x > 0 ? 1 : x < 0 ? -1 : 0);  
} 
 
/*---------------------------------------------------------------------------*/ 
/*---------------------------------------------------------------------------*/ 
int log2 (int x) 
{ 
   int count = 0; 
	 
   while (x > 1)  { 
      x >>= 1; 
      count++; 
   } 
   return count; 
} 
 
 
 
 
/*---------------------------------------------------------------------------*/ 
/*---------------------------------------------------------------------------*/ 
Real FindMax(Real *input, int size) 
{ 
	int i; 
	Real Max=-MaxReal; 
 
	for (i=0; iMax){ 
			Max = input[i]; 
		} 
	} 
	return Max; 
} 
 
 
/*---------------------------------------------------------------------------*/ 
/*---------------------------------------------------------------------------*/ 
Real FindMin(Real *input, int size) 
{ 
	int i; 
	Real Min=MaxReal; 
	 
	for (i=0; i *Max){ 
			*Max=input[i]; 
		} 
	}	 
} 
 
/*---------------------------------------------------------------------------*/ 
/*---------------------------------------------------------------------------*/ 
void WaitKey(void) 
{ 
	getc(stdin); 
} 
 
/*---------------------------------------------------------------------------*/ 
/*----------------------------------------------------------------------------*/	 
int GetFileLength (char *FileName) 
{ 
   struct stat statistics; /* input file statistics */ 
    
   if(stat(FileName,&statistics) == -1) return 0; 
    
   return (int)statistics.st_size; 
} 
 
/*---------------------------------------------------------------------------*/ 
/*----------------------------------------------------------------------------*/	 
void Error(char *fmt, ...) 
{ 
	va_list argptr; 
	 
	va_start( argptr, fmt ); 
	fprintf(stderr, "Error: " ); 
	vprintf( fmt, argptr ); 
	va_end( argptr ); 
	exit( -1 ); 
} 
 
/*----------------------------------------------------------------------------*/	 
void Warning(char *fmt, ...) 
{ 
	va_list argptr; 
	 
	va_start( argptr, fmt ); 
	fprintf( stderr, "Warning: " ); 
	vprintf( fmt, argptr ); 
	va_end( argptr ); 
}