📄 hugecalc.h
字号:
/**********************************************************************
FileDescription: Fast Algorithm Library For Huge Integer.
FileVersion: 2006-09-29
ProductVersion: 6, 0, 0, 3
Portability: ANSI C
Base Classes: None.
Related Document: HugeCalc.chm
Copyright (c) 1992-2006 by Guo XianQiang. All rights reserved.
Web: http://maths.diy.myrice.com/
BBS: http://rd.bbs.xilu.com/
E-Mail: gxqcn@163.com; HugeCalc@Gmail.com
***********************************************************************
If you find any bug or you want to add some useful function
please email to me. Redistribution and use in source are
permitted provided that: source distributions retain this
entire copyright notice and comment.
如果你在使用中发现BUG或添加了功能,请Email我。
你可以使用与发布该文件,但不得进行商业用途(已注册用户除外)。
你的发布要包含完整的本文件头。
附加说明:
1、调用程序所在目录必须为 .../CopyrightByGuoXianqiang[/...]/,否则 HugeCalc.dll 会拒绝任何服务。
2、如需解除上述限制,请在 HugeCalc.chm 中进行“注册”。
3、HugeCalc 最新正式版下载地址为:http://maths.diy.myrice.com/software.htm#02
4、可简单修改下面的宏定义,以定制所需模块集。
5、本导出接口文件可自适应 MBCS / UNICODE 环境。
6、欢迎进行各项测试,如果发现 bug,请及时联系,谢谢!
7、请务必遵守配套的 HugeCalc.chm 的相关声明!
郭先强(gxqcn@163.com; HugeCalc@Gmail.com)
2006-09-29
*/
#if 0 /* 如果无需 HI_xxx 的支持,可:一、将此行修改为“#if 1”;二、或在 dsp 中预定义 _NO_HI */
#ifndef _NO_HI
#define _NO_HI
#endif
#endif
#if 0 /* 如果无需 HX_xxx 的支持,可:一、将此行修改为“#if 1”;二、或在 dsp 中预定义 _NO_HX */
#ifndef _NO_HX
#define _NO_HX
#endif
#endif
#if 0 /* 如果无需 RC_xxx 的支持,可:一、将此行修改为“#if 1”;二、或在 dsp 中预定义 _NO_RC */
#ifndef _NO_RC
#define _NO_RC
#endif
#endif
/* ============================================================================================ */
#if !defined(AFX_HUGECALC_H__99330C8A_F843_4e32_876B_D0DF036B4E05__INCLUDED_)
#define AFX_HUGECALC_H__99330C8A_F843_4e32_876B_D0DF036B4E05__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif /* _MSC_VER > 1000 */
#include < WTYPES.H >
#include < tchar.h >
/* ================ typedef ================ */
#ifndef _SINT32
#define _SINT32
typedef INT32 SINT32;
#endif /* !defined(_SINT32) */
#ifndef _SINT64
#define _SINT64
typedef INT64 SINT64;
#endif /* !defined(_SINT64) */
#ifndef _NO_HI
typedef LPVOID /*const*/ HHUGEINT;
#endif /* #ifndef _NO_HI */
#ifndef _NO_HX
typedef LPVOID /*const*/ HHUGEINTX;
#endif /* #ifndef _NO_HX */
#ifndef _NO_RC
typedef LPVOID /*const*/ HRADIXCONVERTER;
#endif /* #ifndef _NO_RC */
/* ================ enum ================ */
typedef enum tagHCLicenseLevel
{
HC_LICENSE_NONE = -1,
HC_LICENSE_LIMITED = 0,
HC_LICENSE_ALL = 1,
}HCLicenseLevel;
typedef enum tagHCErrCode
{
HCERR_NONE = 0,
HCERR_NO_LICENSE = -1,
HCERR_USER_STOP = -2,
HCERR_OUTOF_MEM = -3,
HCERR_POINTER_INVALID = -4,
HCERR_DIV_ZERO = -5,
HCERR_BASE2SMALL = -6,
HCERR_RADIX2SMALL = -7,
/* ... */
}HCErrCode;
typedef enum tagSIGN
{
SIGN_NEG = -1, /* Negative */
SIGN_ZERO = 0, /* Zero */
SIGN_POS = 1, /* Positive */
}SIGN;
typedef enum tagTimerUnit
{
TIMER_UNIT_ms = 0, /* millisecond */
TIMER_UNIT_us = 1, /* microsecond */
TIMER_UNIT_ns = 2, /* millimicrosecond */
}TimerUnit;
typedef enum tagFormatTime
{
FT_HHMMSS_ms = 0, /* "00:00:12.345" */
FT_DOT06SEC = 1, /* "12.345678" */
FT_DOT06SECs = 2, /* "12.345678s" */
FT_DOT06SEC_s = 3, /* "12.345678 s" */
}FormatTime;
typedef enum tagPrimality
{
COMPOSITE = 0,
PROBABLY_PRIME = 1,
PRIME = 2,
}PRIMALITY;
/* ================ struct ================ */
typedef struct tagUINT32_CVECTOR
{
const UINT32 * p_start;
UINT32 u32Size;
} UINT32_CVECTOR;
#ifndef _NO_HI
typedef struct tagLPCHUGEINT_CVECTOR
{
const HHUGEINT * p_start;
UINT32 u32Size;
} LPCHUGEINT_CVECTOR;
#endif /* #ifndef _NO_HI */
#ifndef _NO_HX
typedef struct tagLPCHUGEINTX_CVECTOR
{
const HHUGEINTX * p_start;
UINT32 u32Size;
} LPCHUGEINTX_CVECTOR;
#endif /* #ifndef _NO_HX */
/* ================ const ================ */
#define FS_NORMAL 0x00 /* normal format */
#define FS_BAND 0x01 /* ' ' or ',' at pre 3[or4] digits from right */
#define FS_BAND_SPACE 0x02 /* must setting "| FS_BAND" */
#define FS_SIGN 0x04 /* even if "+" */
#define FS_SIGN_SPACE 0x08 /* between sign and number */
#define FS_CHAR_LOWER 0x10 /* will use [0-9a-z]; otherwise, use [0-9A-Z] */
#define FS_DEFAULT ( FS_BAND | FS_BAND_SPACE | FS_SIGN_SPACE ) /* default format */
#define _HC_Export_HC 0x00000001 /* 25 functions */
#define _HC_Export_HI 0x00000002 /* 90 functions */
#define _HC_Export_HX 0x00000004 /* 91 functions */
#define _HC_Export_RC 0x00000008 /* 24 functions */
#define _HC_Export_HugeCalc 0x00010000 /* 32 functions */
#define _HC_Export_CHugeInt 0x00020000 /*203 functions */
#define _HC_Export_CHugeIntX 0x00040000 /*204 functions */
#define _HC_Export_CRadixConverter 0x00080000 /* 28 functions */
#define _HC_Export_ANSI_C 0x0000FFFF /*230 functions */
#define _HC_Export_ANSI_CPLUSPLUS 0xFFFF0000 /*467 functions */
#define _HC_Export_All 0xFFFFFFFF /*697 functions */
/* ================ function ================ */
#ifdef __cplusplus
extern "C"
{
#endif
const BOOL hugeCalcDLLInit( const LPCTSTR lpszDLLPath /*= NULL*/ );
void hugeCalcDLLFree( void );
const LPCTSTR HC_getVer( void );
const LPCTSTR HC_getSN( void );
const HCLicenseLevel HC_getLicenseLevel( void );
const UINT32 HC_getExportFunNums( const UINT32 u32Mask /*= _HC_Export_ANSI_C*/ );
const HCErrCode HC_getLastError( void );
/* It usefull when use multithread. */
void HC_setTerminate( const BOOL bTerminate /*= TRUE*/ );
const BOOL HC_isTerminated( void );
void HC_seedRandom( const UINT32 u32Seed /*= 0*/ );
/* before calculate, pls call bEnableTimer as TRUE, and after finishing call as FALSE */
void HC_resetTimer( const UINT32 u32Timer /*= 0*/, const TimerUnit enumTimerUnit /*= TIMER_UNIT_us*/ );
void HC_enableTimer( const BOOL bEnableTimer /*= TRUE*/ );
const UINT32 HC_getTimer( const TimerUnit enumTimerUnit /*= TIMER_UNIT_us*/ );
const LPCTSTR HC_getTimerStr( const FormatTime enumFormatTime /*= FT_DOT06SEC_s*/ );
const BOOL HC_isPrime( const UINT32 u32Num );
const UINT32 HC_getPrimePi( const UINT32 u32Num );
const UINT32 HC_getPrime( const UINT32 u32Index );
const UINT32 HC_getPrimeCount( const UINT32 u32LBound, const UINT32 u32UBound );
const UINT32 HC_getPrimeList( UINT32 * const lpPrimeBuffer, const UINT32 u32BufferSize, const UINT32 u32LBound, const UINT32 u32UBound );
/* Returns the largest prime number less than the argument. */
const SINT32 HC_previousPrime( const SINT32 s32Benchmark );
/* Returns the smallest prime number greater than the argument. */
const SINT32 HC_nextPrime( const SINT32 s32Benchmark );
/* Greatest Common Divisor */
const UINT32 HC_gcd( const UINT32 u32Num1, const UINT32 u32Num2 );
const UINT32 HC_gcd_v32( const UINT32_CVECTOR vU32Num );
/* GcdEx: g = GcdEx( x, y, u, v ) = u * x + v * y. g is always positive, even if one or both of u and v are negative. */
const UINT32 HC_gcdEx( SINT32 * const x, SINT32 * const y, const SINT32 u, const SINT32 v );
const UINT32 HC_invertMod( const UINT32 u32InvertBase, const UINT32 u32Mod );
/* Lowest Common Multiple */
const UINT64 HC_lcm( const UINT32 u32Num1, const UINT32 u32Num2 );
/* PowMod */
const UINT32 HC_powMod( const UINT32 u32Base, const UINT32 u32Exp, const UINT32 u32Mod );
#ifndef _NO_HI
/* constructor */
HHUGEINT HI_new( void );
/* destructor */
void HI_delete( HHUGEINT hHugeInt );
const UINT32 HI_getCount( void );
/* reload operators */
HHUGEINT HI_set_s32( HHUGEINT hHugeInt, const SINT32 s32Num );
HHUGEINT HI_set_s64( HHUGEINT hHugeInt, const SINT64 s64Num );
HHUGEINT HI_set_u32( HHUGEINT hHugeInt, const UINT32 u32Num );
HHUGEINT HI_set_u64( HHUGEINT hHugeInt, const UINT64 u64Num );
HHUGEINT HI_set_str( HHUGEINT hHugeInt, const LPCTSTR lpszNum );
HHUGEINT HI_set_hi( HHUGEINT hHugeInt, const HHUGEINT hRight );
#ifndef _NO_HX
HHUGEINT HI_set_hx( HHUGEINT hHugeInt, const HHUGEINTX hRight );
#endif /* #ifndef _NO_HX */
#ifndef _NO_RC
HHUGEINT HI_set_rc( HHUGEINT hHugeInt, const HRADIXCONVERTER hRight );
#endif /* #ifndef _NO_RC */
HHUGEINT HI_setHexStr( HHUGEINT hHugeInt, const LPCTSTR lpszHexNum );
/* Return non-zero if the value of (*this) fits in SINT32, UINT32, SINT64 or UINT64, respectively. Otherwise, return zero. */
const SINT32 HI_get_s32( const HHUGEINT hHugeInt );
const SINT64 HI_get_s64( const HHUGEINT hHugeInt );
const UINT32 HI_get_u32( const HHUGEINT hHugeInt );
const UINT64 HI_get_u64( const HHUGEINT hHugeInt );
/* CompareAbs */
const SINT32 HI_compareAbs_s32( const HHUGEINT hLeft, const SINT32 s32Num );
const SINT32 HI_compareAbs_u32( const HHUGEINT hLeft, const UINT32 u32Num );
const SINT32 HI_compareAbs_hi( const HHUGEINT hLeft, const HHUGEINT hRight );
/* Compare */
const SINT32 HI_compare_s32( const HHUGEINT hLeft, const SINT32 s32Num );
const SINT32 HI_compare_u32( const HHUGEINT hLeft, const UINT32 u32Num );
const SINT32 HI_compare_hi( const HHUGEINT hLeft, const HHUGEINT hRight );
/* get property */
const SIGN HI_getSign( const HHUGEINT hHugeInt );
const BOOL HI_isZero( const HHUGEINT hHugeInt );
const BOOL HI_isAbsOne( const HHUGEINT hHugeInt );
const BOOL HI_isOdd( const HHUGEINT hHugeInt );
const BOOL HI_isEven( const HHUGEINT hHugeInt );
const BOOL HI_isPrime( const HHUGEINT hHugeInt );
const BOOL HI_isPrime( const HHUGEINT hHugeInt );
const PRIMALITY HI_testPrimality( const HHUGEINT hHugeInt, const UINT32 u32Repeat /*= 5*/ );
const UINT32 HI_getBits( const HHUGEINT hHugeInt );
const UINT32 HI_getDigits( const HHUGEINT hHugeInt );
const UINT32 HI_getTailDecZeros( const HHUGEINT hHugeInt );
HHUGEINT HI_bitLShift( HHUGEINT hHugeInt, const UINT32 u32BitLShift );
HHUGEINT HI_bitRShift( HHUGEINT hHugeInt, const UINT32 u32BitRShift );
/* notice: base on decimal system !! */
HHUGEINT HI_decLShift( HHUGEINT hHugeInt, const UINT32 u32DecLShift );
HHUGEINT HI_decRShift( HHUGEINT hHugeInt, const UINT32 u32DecRShift );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -