📄 global.h
字号:
#ifndef __GLOBAL_H_
#define __GLOBAL_H_
#ifdef __cplusplus
extern "C" {
#endif
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*
* 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.
*
*/
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* disable unused variabled warning */
#pragma warning (disable : 4101)
#include <math.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <assert.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <time.h>
#include <string.h>
#include "memchk.h"
typedef enum {FALSE, TRUE} Boolean;
typedef unsigned long ULONG;
#define __USE_FLOAT_ 1
#if __USE_FLOAT_
typedef float Real;
typedef float REAL;
#define MaxReal ((float)3.40282346638528860e+38)
#define MinReal ((float)1.17549435082228750e-38)
#else
typedef double Real;
typedef double REAL;
#define MaxReal 1.7976931348623157e+308
#define MinReal 2.2250738585072014e-308
#endif
#define eps 1.e-15
typedef unsigned char UCHAR;
typedef int INT32;
#define MAX_PATH _MAX_PATH
// note : (int)(-2.3) gives -2
// floor of -2.3 is -3
// so we do have to minus -0.5 for negative numbers to get their floor
#define MIN(x,y) (((x)<(y))?(x):(y))
#define MAX(x,y) (((x)>(y))?(x):(y))
#define ROUND(a) (((a)<0)?(int)((a)-0.5):(int)((a)+0.5))
#define BOUND(a) ((a)<0.0? 0 : ((a)>255.0? 255 : a))
#define RINT(x) (int)floor(x+0.5) // same as ROUND
#define SIGN(x) (x>0? 1: (x<0? -1: 0))
/* GCC - math.h */
#define M_E 2.7182818284590452354 /* e^1 */
#define M_LOG2E 1.4426950408889634074 /* log_2 (e^1) */
#define M_LOG10E 0.43429448190325182765 /* log_10 (e^1) */
#define M_LN2 0.69314718055994530942 /* log_e (2) */
#define M_LN10 2.30258509299404568402 /* log_e (10) */
#define M_PI 3.14159265358979323846 /* pi */
#define M_PI_2 1.57079632679489661923 /* pi/2 */
#define M_PI_4 0.78539816339744830962 /* pi/4 */
#define M_1_PI 0.31830988618379067154 /* 1/pi */
#define M_2_PI 0.63661977236758134308 /* 2/pi */
#define M_2_SQRTPI 1.12837916709551257390 /* */
#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
#define M_SQRT1_2 0.70710678118654752440 /* sqrt(1/2) */
#define PI M_PI /* pi */
#define PI2 M_PI_2 /* pi/2 */
#define SQRT2 M_SQRT2 /* sqrt(2) */
#define ONELOG2 M_LOG2E /* 1/log_e (2) */
Real MOD (Real x, Real N);
Real square (Real x);
int isquare (int x);
int sign(Real x);
int Log2 (int x);
int NumberOfBits(int x);
Real FindMax(Real *input, int size);
Real FindAbsMax(Real *input, int size);
int iFindAbsMax(int *input, int size);
int iFindMax(int *input, int size);
int iFindMin(int *input, int size);
Real FindMin(Real *input, int size);
void FindMaxMin(Real *input, int size, Real *Max, Real *Min);
void iFindMaxMin(int *input, int size, int *Max, int *Min);
void ScaleArray(Real *input, int size, double scale);
Real Sum(Real *input, int size);
void AddValue(Real *input, int size, double value);
void WaitKey(void);
int GetFileLength (char *FileName);
int realToInt (double x, int precision);
double intToReal (int n, int precision);
double RoundReal(double x, int precision);
void ReadLine(char *prompt, char *line);
int ReadInteger(char *prompt);
double ReadDouble(char *prompt);
int ReadYesNo(char *prompt);
Real ReadReal(char *prompt);
void Error(char *fmt, ...);
void Warning(char *fmt, ...);
/*--------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------*/
typedef struct ArrayRealStruct{
int xsize;
int ysize;
int zsize;
REAL *a;
} ArrayReal;
/*--------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------*/
typedef struct ArrayUCharStruct{
int xsize;
int ysize;
int zsize;
UCHAR *a;
} ArrayUChar;
/*--------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------*/
typedef struct ArrayInt32Struct{
int xsize;
int ysize;
int zsize;
INT32 *a;
} ArrayInt32;
/*--------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------*/
ArrayReal *ArrayRealAlloc(int xsize, int ysize, int zsize);
void ArrayRealFree(ArrayReal *A);
REAL ArrayRealGetVal(ArrayReal *A, int x, int y, int z);
void ArrayRealPutVal(ArrayReal *A, int x, int y, int z, REAL val);
ArrayUChar *ArrayUCharAlloc(int xsize, int ysize, int zsize);
void ArrayUCharFree(ArrayUChar *A);
UCHAR ArrayUCharGetVal(ArrayUChar *A, int x, int y, int z);
void ArrayUCharPutVal(ArrayUChar *A, int x, int y, int z, UCHAR val);
ArrayInt32 *ArrayInt32Alloc(int xsize, int ysize, int zsize);
void ArrayInt32Free(ArrayInt32 *A);
INT32 ArrayInt32GetVal(ArrayInt32 *A, int x, int y, int z);
void ArrayInt32PutVal(ArrayInt32 *A, int x, int y, int z, INT32 val);
/*--------------------------------------------------------------------------------------------*/
void ExtractProgramName(char *NameOnly, char *FullPath);
/*--------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------*/
/* code from A. Said and W. Pearlman (SPIHT) */
typedef struct TimerStruc{
int stat; /* chronometer status: 0 = off, 1 = on */
int mark, elp; /* initial and elapsed time */
} Timer;
void InitTimer(Timer *c);
void ResetTimer(Timer *c);
void StartTimer(Timer *c, char *s);
void StopTimer(Timer *c);
REAL ReadTimer(Timer *c);
void DisplayTimer(Timer *c, char *s);
#ifndef CLOCKS_PER_SEC
#define CLOCKS_PER_SEC 1e6
#endif
#ifdef __cplusplus
}
#endif
/*--------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------*/
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -