⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slarith.c

📁 一个C格式的脚本处理函数库源代码,可让你的C程序具有执行C格式的脚本文件
💻 C
📖 第 1 页 / 共 4 页
字号:
#endifTO_DOUBLE_FUN(float_to_one_double,float)TO_DOUBLE_FUN(double_to_one_double,double)SLang_To_Double_Fun_TypeSLarith_get_to_double_fun (unsigned char type, unsigned int *sizeof_type){   unsigned int da;   SLang_To_Double_Fun_Type to_double;   switch (type)     {      default:	return NULL;      case SLANG_CHAR_TYPE:	da = sizeof (char); to_double = char_to_one_double;	break;      case SLANG_UCHAR_TYPE:	da = sizeof (unsigned char); to_double = uchar_to_one_double;	break;      case SLANG_SHORT_TYPE:	da = sizeof (short); to_double = short_to_one_double;	break;      case SLANG_USHORT_TYPE:	da = sizeof (unsigned short); to_double = ushort_to_one_double;	break;      case SLANG_INT_TYPE:	da = sizeof (int); to_double = int_to_one_double;	break;      case SLANG_UINT_TYPE:	da = sizeof (unsigned int); to_double = uint_to_one_double;	break;      case SLANG_LONG_TYPE:	da = sizeof (long); to_double = long_to_one_double;	break;      case SLANG_ULONG_TYPE:	da = sizeof (unsigned long); to_double = ulong_to_one_double;	break;      case SLANG_FLOAT_TYPE:	da = sizeof (float); to_double = float_to_one_double;	break;     case SLANG_DOUBLE_TYPE:	da = sizeof (double); to_double = double_to_one_double;	break;     }   if (sizeof_type != NULL) *sizeof_type = da;   return to_double;}#endif				       /* SLANG_HAS_FLOAT *//* Each element of the matrix determines how the row maps onto the column. * That is, let the matrix be B_ij.  Where the i,j indices refer to * precedence of the type.  Then, * B_ij->copy_function copies type i to type j.  Similarly, * B_ij->convert_function mallocs a new array of type j and copies i to it. * * Since types are always converted to higher levels of precedence for binary * operations, many of the elements are NULL. * * Is the idea clear? */typedef struct{   FVOID_STAR copy_function;   Convert_Fun_Type convert_function;}Binary_Matrix_Type;static Binary_Matrix_Type Binary_Matrix [MAX_ARITHMETIC_TYPES][MAX_ARITHMETIC_TYPES] ={     {	  {(FVOID_STAR)copy_char_to_char, NULL},	  {(FVOID_STAR)copy_char_to_char, NULL},	{(FVOID_STAR) copy_char_to_short, NULL},	{(FVOID_STAR) copy_char_to_ushort, NULL},	{(FVOID_STAR) copy_char_to_int, char_to_int},	{(FVOID_STAR) copy_char_to_uint, char_to_uint},	{(FVOID_STAR) copy_char_to_long, char_to_long},	{(FVOID_STAR) copy_char_to_ulong, char_to_ulong},#if SLANG_HAS_FLOAT	{(FVOID_STAR) copy_char_to_float, char_to_float},	{(FVOID_STAR) copy_char_to_double, char_to_double},#endif     },     {	  {(FVOID_STAR)copy_char_to_char, NULL},	  {(FVOID_STAR)copy_char_to_char, NULL},	{(FVOID_STAR) copy_uchar_to_short, NULL},	{(FVOID_STAR) copy_uchar_to_ushort, NULL},	{(FVOID_STAR) copy_uchar_to_int, uchar_to_int},	{(FVOID_STAR) copy_uchar_to_uint, uchar_to_uint},	{(FVOID_STAR) copy_uchar_to_long, uchar_to_long},	{(FVOID_STAR) copy_uchar_to_ulong, uchar_to_ulong},#if SLANG_HAS_FLOAT	{(FVOID_STAR) copy_uchar_to_float, uchar_to_float},	{(FVOID_STAR) copy_uchar_to_double, uchar_to_double},#endif     },     {	{(FVOID_STAR) copy_short_to_char, NULL},	{(FVOID_STAR) copy_short_to_uchar, NULL},	{(FVOID_STAR) copy_short_to_short, NULL},	{(FVOID_STAR) copy_short_to_short, NULL},	{(FVOID_STAR) copy_short_to_int, short_to_int},	{(FVOID_STAR) copy_short_to_uint, short_to_uint},	{(FVOID_STAR) copy_short_to_long, short_to_long},	{(FVOID_STAR) copy_short_to_ulong, short_to_ulong},#if SLANG_HAS_FLOAT	{(FVOID_STAR) copy_short_to_float, short_to_float},	{(FVOID_STAR) copy_short_to_double, short_to_double},#endif     },     {	{(FVOID_STAR) copy_ushort_to_char, NULL},	{(FVOID_STAR) copy_ushort_to_uchar, NULL},	{(FVOID_STAR) copy_short_to_short, NULL},	{(FVOID_STAR) copy_short_to_short, NULL},	{(FVOID_STAR) copy_ushort_to_int, ushort_to_int},	{(FVOID_STAR) copy_ushort_to_uint, ushort_to_uint},	{(FVOID_STAR) copy_ushort_to_long, ushort_to_long},	{(FVOID_STAR) copy_ushort_to_ulong, ushort_to_ulong},#if SLANG_HAS_FLOAT	{(FVOID_STAR) copy_ushort_to_float, ushort_to_float},	{(FVOID_STAR) copy_ushort_to_double, ushort_to_double},#endif     },     {	{(FVOID_STAR) copy_int_to_char, NULL},	{(FVOID_STAR) copy_int_to_uchar, NULL},	{(FVOID_STAR) copy_int_to_short, NULL},	{(FVOID_STAR) copy_int_to_ushort, NULL},	{(FVOID_STAR) copy_int_to_int, NULL},	{(FVOID_STAR) copy_int_to_int, NULL},	{(FVOID_STAR) copy_int_to_long, int_to_long},	{(FVOID_STAR) copy_int_to_ulong, int_to_ulong},#if SLANG_HAS_FLOAT	{(FVOID_STAR) copy_int_to_float, int_to_float},	{(FVOID_STAR) copy_int_to_double, int_to_double},#endif     },     {	{(FVOID_STAR) copy_uint_to_char, NULL},	{(FVOID_STAR) copy_uint_to_uchar, NULL},	{(FVOID_STAR) copy_uint_to_short, NULL},	{(FVOID_STAR) copy_uint_to_ushort, NULL},	{(FVOID_STAR) copy_int_to_int, NULL},	{(FVOID_STAR) copy_int_to_int, NULL},	{(FVOID_STAR) copy_uint_to_long, uint_to_long},	{(FVOID_STAR) copy_uint_to_ulong, uint_to_ulong},#if SLANG_HAS_FLOAT	{(FVOID_STAR) copy_uint_to_float, uint_to_float},	{(FVOID_STAR) copy_uint_to_double, uint_to_double},#endif     },     {	{(FVOID_STAR) copy_long_to_char, NULL},	{(FVOID_STAR) copy_long_to_uchar, NULL},	{(FVOID_STAR) copy_long_to_short, NULL},	{(FVOID_STAR) copy_long_to_ushort, NULL},	{(FVOID_STAR) copy_long_to_int, NULL},	{(FVOID_STAR) copy_long_to_uint, NULL},	{(FVOID_STAR) copy_long_to_long, NULL},	{(FVOID_STAR) copy_long_to_long, NULL},#if SLANG_HAS_FLOAT	{(FVOID_STAR) copy_long_to_float, long_to_float},	{(FVOID_STAR) copy_long_to_double, long_to_double},#endif     },     {	{(FVOID_STAR) copy_ulong_to_char, NULL},	{(FVOID_STAR) copy_ulong_to_uchar, NULL},	{(FVOID_STAR) copy_ulong_to_short, NULL},	{(FVOID_STAR) copy_ulong_to_ushort, NULL},	{(FVOID_STAR) copy_ulong_to_int, NULL},	{(FVOID_STAR) copy_ulong_to_uint, NULL},	{(FVOID_STAR) copy_long_to_long, NULL},	{(FVOID_STAR) copy_long_to_long, NULL},#if SLANG_HAS_FLOAT	{(FVOID_STAR) copy_ulong_to_float, ulong_to_float},	{(FVOID_STAR) copy_ulong_to_double, ulong_to_double},#endif     },#if SLANG_HAS_FLOAT     {	{(FVOID_STAR) copy_float_to_char, NULL},	{(FVOID_STAR) copy_float_to_uchar, NULL},	{(FVOID_STAR) copy_float_to_short, NULL},	{(FVOID_STAR) copy_float_to_ushort, NULL},	{(FVOID_STAR) copy_float_to_int, NULL},	{(FVOID_STAR) copy_float_to_uint, NULL},	{(FVOID_STAR) copy_float_to_long, NULL},	{(FVOID_STAR) copy_float_to_ulong, NULL},	{(FVOID_STAR) copy_float_to_float, NULL},	{(FVOID_STAR) copy_float_to_double, float_to_double},     },     {	{(FVOID_STAR) copy_double_to_char, NULL},	{(FVOID_STAR) copy_double_to_uchar, NULL},	{(FVOID_STAR) copy_double_to_short, NULL},	{(FVOID_STAR) copy_double_to_ushort, NULL},	{(FVOID_STAR) copy_double_to_int, NULL},	{(FVOID_STAR) copy_double_to_uint, NULL},	{(FVOID_STAR) copy_double_to_long, NULL},	{(FVOID_STAR) copy_double_to_ulong, NULL},	{(FVOID_STAR) copy_double_to_float, NULL},	{(FVOID_STAR) copy_double_to_double, NULL},     }#endif};#define GENERIC_BINARY_FUNCTION int_int_bin_op#define GENERIC_BIT_OPERATIONS#define GENERIC_TYPE int#define POW_FUNCTION(a,b) pow((double)(a),(double)(b))#define POW_RESULT_TYPE double#define ABS_FUNCTION abs#define MOD_FUNCTION(a,b) ((a) % (b))#define GENERIC_UNARY_FUNCTION int_unary_op#define SIGN_FUNCTION(x) (((x) > 0) ? 1 : (((x) < 0) ? -1 : 0))#if _SLANG_OPTIMIZE_FOR_SPEED# define SCALAR_BINARY_FUNCTION int_int_scalar_bin_op#endif#define PUSH_SCALAR_OBJ_FUN(x) SLclass_push_int_obj(SLANG_INT_TYPE,(x))#define PUSH_POW_OBJ_FUN(x) SLclass_push_double_obj(SLANG_DOUBLE_TYPE, (x))#define CMP_FUNCTION int_cmp_function#include "slarith.inc"#define GENERIC_BINARY_FUNCTION uint_uint_bin_op#define GENERIC_BIT_OPERATIONS#define GENERIC_TYPE unsigned int#define POW_FUNCTION(a,b) pow((double)(a),(double)(b))#define POW_RESULT_TYPE double#define MOD_FUNCTION(a,b) ((a) % (b))#define GENERIC_UNARY_FUNCTION uint_unary_op#define ABS_FUNCTION(a) (a)#define SIGN_FUNCTION(x) (((x) > 0) ? 1 : 0)#if _SLANG_OPTIMIZE_FOR_SPEED# define SCALAR_BINARY_FUNCTION uint_uint_scalar_bin_op#endif#define PUSH_SCALAR_OBJ_FUN(x) SLclass_push_int_obj(SLANG_UINT_TYPE,(int)(x))#define PUSH_POW_OBJ_FUN(x) SLclass_push_double_obj(SLANG_DOUBLE_TYPE, (x))#define CMP_FUNCTION uint_cmp_function#include "slarith.inc"#if SIZEOF_LONG != SIZEOF_INT#define GENERIC_BINARY_FUNCTION long_long_bin_op#define GENERIC_BIT_OPERATIONS#define GENERIC_TYPE long#define POW_FUNCTION(a,b) pow((double)(a),(double)(b))#define POW_RESULT_TYPE double#define MOD_FUNCTION(a,b) ((a) % (b))#define GENERIC_UNARY_FUNCTION long_unary_op#define ABS_FUNCTION(a) (((a) >= 0) ? (a) : -(a))#define SIGN_FUNCTION(x) (((x) > 0) ? 1 : (((x) < 0) ? -1 : 0))#if _SLANG_OPTIMIZE_FOR_SPEED# define SCALAR_BINARY_FUNCTION long_long_scalar_bin_op#endif#define PUSH_SCALAR_OBJ_FUN(x) SLclass_push_long_obj(SLANG_LONG_TYPE,(x))#define PUSH_POW_OBJ_FUN(x) SLclass_push_double_obj(SLANG_DOUBLE_TYPE, (x))#define CMP_FUNCTION long_cmp_function#include "slarith.inc"#define GENERIC_BINARY_FUNCTION ulong_ulong_bin_op#define GENERIC_BIT_OPERATIONS#define GENERIC_TYPE unsigned long#define POW_FUNCTION(a,b) pow((double)(a),(double)(b))#define POW_RESULT_TYPE double#define MOD_FUNCTION(a,b) ((a) % (b))#define GENERIC_UNARY_FUNCTION ulong_unary_op#define ABS_FUNCTION(a) (a)#define SIGN_FUNCTION(x) (((x) > 0) ? 1 : 0)#if _SLANG_OPTIMIZE_FOR_SPEED# define SCALAR_BINARY_FUNCTION ulong_ulong_scalar_bin_op#endif#define PUSH_SCALAR_OBJ_FUN(x) SLclass_push_long_obj(SLANG_ULONG_TYPE,(long)(x))#define PUSH_POW_OBJ_FUN(x) SLclass_push_double_obj(SLANG_DOUBLE_TYPE, (x))#define CMP_FUNCTION ulong_cmp_function#include "slarith.inc"#else#define long_long_bin_op	int_int_bin_op#define ulong_ulong_bin_op	uint_uint_bin_op#define long_unary_op		int_unary_op#define ulong_unary_op		uint_unary_op#define long_cmp_function	int_cmp_function#define ulong_cmp_function	uint_cmp_function#endif				       /* SIZEOF_INT != SIZEOF_LONG */#if SLANG_HAS_FLOAT#define GENERIC_BINARY_FUNCTION float_float_bin_op#define GENERIC_TYPE float#define POW_FUNCTION(a,b) (float)pow((double)(a),(double)(b))#define POW_RESULT_TYPE float#define MOD_FUNCTION(a,b) (float)fmod((a),(b))#define GENERIC_UNARY_FUNCTION float_unary_op#define ABS_FUNCTION(a) (float)fabs((double) a)#define SIGN_FUNCTION(x) (((x) > 0) ? 1 : (((x) < 0) ? -1 : 0))#if _SLANG_OPTIMIZE_FOR_SPEED# define SCALAR_BINARY_FUNCTION float_float_scalar_bin_op#endif#define PUSH_SCALAR_OBJ_FUN(x) SLclass_push_float_obj(SLANG_FLOAT_TYPE,(x))#define PUSH_POW_OBJ_FUN(x) SLclass_push_float_obj(SLANG_FLOAT_TYPE, (x))#define CMP_FUNCTION float_cmp_function#include "slarith.inc"#define GENERIC_BINARY_FUNCTION double_double_bin_op#define GENERIC_TYPE double#define POW_FUNCTION(a,b) pow((double)(a),(double)(b))#define POW_RESULT_TYPE double#define MOD_FUNCTION(a,b) (float)fmod((a),(b))#define GENERIC_UNARY_FUNCTION double_unary_op#define ABS_FUNCTION(a) fabs(a)#define SIGN_FUNCTION(x) (((x) > 0) ? 1 : (((x) < 0) ? -1 : 0))#if _SLANG_OPTIMIZE_FOR_SPEED# define SCALAR_BINARY_FUNCTION double_double_scalar_bin_op#endif#define PUSH_SCALAR_OBJ_FUN(x) SLclass_push_double_obj(SLANG_DOUBLE_TYPE,(x))#define PUSH_POW_OBJ_FUN(x) SLclass_push_double_obj(SLANG_DOUBLE_TYPE, (x))#define CMP_FUNCTION double_cmp_function#include "slarith.inc"#endif				       /* SLANG_HAS_FLOAT */#define GENERIC_UNARY_FUNCTION char_unary_op#define GENERIC_BIT_OPERATIONS#define GENERIC_TYPE signed char#define ABS_FUNCTION abs#define SIGN_FUNCTION(x) (((x) > 0) ? 1 : (((x) < 0) ? -1 : 0))#define CMP_FUNCTION char_cmp_function#include "slarith.inc"#define GENERIC_UNARY_FUNCTION uchar_unary_op#define GENERIC_BIT_OPERATIONS#define GENERIC_TYPE unsigned char#define ABS_FUNCTION(x) (x)#define SIGN_FUNCTION(x) (((x) > 0) ? 1 : 0)#define CMP_FUNCTION uchar_cmp_function#include "slarith.inc"#if SIZEOF_SHORT != SIZEOF_INT#define GENERIC_UNARY_FUNCTION short_unary_op#define GENERIC_BIT_OPERATIONS#define GENERIC_TYPE short#define ABS_FUNCTION abs#define SIGN_FUNCTION(x) (((x) > 0) ? 1 : (((x) < 0) ? -1 : 0))#define CMP_FUNCTION short_cmp_function#include "slarith.inc"#define GENERIC_UNARY_FUNCTION ushort_unary_op#define GENERIC_BIT_OPERATIONS#define GENERIC_TYPE unsigned short#define ABS_FUNCTION(x) (x)#define SIGN_FUNCTION(x) (((x) > 0) ? 1 : 0)#define CMP_FUNCTION ushort_cmp_function#include "slarith.inc"#endif				       /* SIZEOF_INT != SIZEOF_SHORT *//* Unfortunately, the numbers that were assigned to the data-types were * not well thought out.  So, I need to use the following table. */#define MAXIMUM_ARITH_TYPE_VALUE	SLANG_FLOAT_TYPE#define IS_INTEGER_TYPE(x) \  (((x) <= MAXIMUM_ARITH_TYPE_VALUE) \      && (Type_Precedence_Table[x] < 8) && (Type_Precedence_Table[x] != -1))#define IS_ARITHMETIC_TYPE(x) \  (((x) <= MAXIMUM_ARITH_TYPE_VALUE) && (Type_Precedence_Table[x] != -1))#define LONG_PRECEDENCE_VALUE	6#define FLOAT_PRECEDENCE_VALUE	8static signed char Type_Precedence_Table [MAXIMUM_ARITH_TYPE_VALUE + 1] ={   -1,				       /* SLANG_UNDEFINED_TYPE */   -1,				       /* SLANG_VOID_TYPE */   4,				       /* SLANG_INT_TYPE */#if SLANG_HAS_FLOAT   9,				       /* SLANG_DOUBLE_TYPE */#else   -1,#endif   0,				       /* SLANG_CHAR_TYPE */   -1,				       /* SLANG_INTP_TYPE */   -1,				       /* SLANG_REF_TYPE */   -1,				       /* SLANG_COMPLEX_TYPE */   -1,				       /* SLANG_NULL_TYPE */   1,				       /* SLANG_UCHAR_TYPE */   2,				       /* SLANG_SHORT_TYPE */   3,				       /* SLANG_USHORT_TYPE */   5,				       /* SLANG_UINT_TYPE */   6,				       /* SLANG_LONG_TYPE */   7,				       /* SLANG_ULONG_TYPE */   -1,				       /* SLANG_STRING_TYPE */#if SLANG_HAS_FLOAT   8				       /* SLANG_FLOAT_TYPE */#else  -1#endif};int _SLarith_get_precedence (unsigned char type){   if (type > MAXIMUM_ARITH_TYPE_VALUE)     return -1;   return Type_Precedence_Table[type];}unsigned char _SLarith_promote_type (unsigned char t){   switch (t)     {      case SLANG_FLOAT_TYPE:      case SLANG_DOUBLE_TYPE:      case SLANG_LONG_TYPE:      case SLANG_ULONG_TYPE:      case SLANG_INT_TYPE:      case SLANG_UINT_TYPE:	break;      case SLANG_USHORT_TYPE:#if SIZEOF_INT == SIZEOF_SHORT	t = SLANG_UINT_TYPE;	break;#endif	/* drop */      case SLANG_CHAR_TYPE:      case SLANG_UCHAR_TYPE:      case SLANG_SHORT_TYPE:      default:	t = SLANG_INT_TYPE;

⌨️ 快捷键说明

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