clongint.h

来自「一个用来对非常大的数进行科学计算的程序库」· C头文件 代码 · 共 99 行

H
99
字号
//  This program is a class for long number computing with no limit.
#ifndef MELON_CLONGINT_H
#define MELON_CLONGINT_H

//struct tagCLONGINT_DIVIDERESULT;
typedef struct tagCLONGINT_DIVIDERESULT DIVIDERESULT, FAR * LPDIVIDERESULT, * PDIVIDERESULT;

// Definition the CLongInt class
class CLongInt
{
protected:
    CString m_csInt;
	BOOL    m_bSign;
	static const char sCharSet[];
	
public:
	// Initialize Functions
	CLongInt();
	CLongInt(long nNum);
	CLongInt(const char *lpszNumStr);
	CLongInt(const CString & cs);
	CLongInt(const CLongInt & li);
	
	virtual ~CLongInt();
	
public:
	// I/O Function
	CString GetNumString() const;
	
public:
	// Calc Operator Overload
	CLongInt & operator = (long nNum);
	CLongInt & operator = (const CLongInt & li);
	
	CLongInt operator + (long nNum)       const;
	CLongInt operator + (const CLongInt & li)     const;
	friend CLongInt operator + (long x, const CLongInt & y);
	
	CLongInt operator - (long nNum)       const;
	CLongInt operator - (const CLongInt & li)     const;
	friend CLongInt operator - (long n, const CLongInt & li);
	
	CLongInt operator - ()                const;
	
	CLongInt operator * (long n)          const;
	CLongInt operator * (const CLongInt & li)     const;
	friend CLongInt operator * (long n, const CLongInt & li);

    friend DIVIDERESULT Div(const CLongInt & liBei1, const CLongInt & liChu1);
	//CLongInt operator / (const CLongInt & liChu)     const;
	
	CLongInt operator += (long n);
	CLongInt operator += (const CLongInt & li);
	CLongInt operator -= (long n);
	CLongInt operator -= (const CLongInt & li);
	CLongInt operator *= (long n);
	CLongInt operator *= (const CLongInt & li);
	
	// Basic Compare Operator Overload
	BOOL operator >  (long n)         const;
	BOOL operator <  (long n)         const;
	BOOL operator >= (long n)         const;
	BOOL operator <= (long n)         const;
	BOOL operator == (long n)         const;
	BOOL operator != (long n)         const;
	BOOL operator >  (const CLongInt & li)    const;
	BOOL operator <  (const CLongInt & li)    const;
	BOOL operator >= (const CLongInt & li)    const;
	BOOL operator <= (const CLongInt & li)    const;
	BOOL operator == (const CLongInt & li)    const;
	BOOL operator != (const CLongInt & li)    const;
	
private:
	BOOL IsNum(const char * lpszNumStr) const;
	CString ToRegularNumStr(const char * lpszNumStr) const;
	inline int GetLeft(int x) const;

};

// Definition the Exception class

class CLongIntException : public CException
{};

class CLongIntIsNotNumberException : public CLongIntException
{};

class CLongIntDivException : public CLongIntException
{};

// Definition the DivideResult struct
struct tagCLONGINT_DIVIDERESULT
{
	CLongInt liQuotient;
	CLongInt liModulus;
};

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?