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

📄 bmathfun.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
   /* and each argument is checked to prevent a divide by */   /* zero error.                                         */   /*=====================================================*/   while (theExpression != NULL)     {      if (! GetNumericArgument(theExpression,"div",&theArgument,CLIPS_FALSE,pos)) theExpression = NULL;      else theExpression = GetNextArgument(theExpression);      if (theArgument.type == INTEGER) theNumber = ValueToLong(theArgument.value);      else if (theArgument.type == FLOAT) theNumber = (long) ValueToDouble(theArgument.value);      else theNumber = 1;            if (theNumber == 0L)        {         DivideByZeroErrorMessage("div");         SetHaltExecution(CLIPS_TRUE);         SetEvaluationError(CLIPS_TRUE);         return(1L);        }      if (theArgument.type == INTEGER)        { total /= ValueToLong(theArgument.value); }      else        { total = total / (long) ValueToDouble(theArgument.value); }      pos++;     }   /*======================================================*/   /* The result of the div function is always an integer. */   /*======================================================*/      return(total);  }/*****************************************************//* SetAutoFloatDividendCommand: CLIPS access routine *//*   for the set-auto-float-dividend command.        *//*****************************************************/globle int SetAutoFloatDividendCommand()  {   int oldValue;   DATA_OBJECT theArgument;   /*===============================*/   /* Remember the present setting. */   /*===============================*/      oldValue = AutoFloatDividend;   /*============================================*/   /* Check for the correct number of arguments. */   /*============================================*/      if (ArgCountCheck("set-auto-float-dividend",EXACTLY,1) == -1)     { return(oldValue); }   RtnUnknown(1,&theArgument);   /*============================================================*/   /* The symbol FALSE disables the auto float dividend feature. */   /*============================================================*/      if ((theArgument.value == CLIPSFalseSymbol) && (theArgument.type == SYMBOL))     { AutoFloatDividend = CLIPS_FALSE; }   else     { AutoFloatDividend = CLIPS_TRUE; }   /*======================================*/   /* Return the old value of the feature. */   /*======================================*/      return(oldValue);  }/*****************************************************//* GetAutoFloatDividendCommand: CLIPS access routine *//*   for the get-auto-float-dividend command.        *//*****************************************************/globle int GetAutoFloatDividendCommand()  {   /*============================================*/   /* Check for the correct number of arguments. */   /*============================================*/      ArgCountCheck("get-auto-float-dividend",EXACTLY,0);   /*=============================*/   /* Return the current setting. */   /*=============================*/      return(AutoFloatDividend);  }/**********************************************//* GetAutoFloatDividend: C access routine for *//*   the get-auto-float-dividend command.     *//**********************************************/globle BOOLEAN GetAutoFloatDividend()  {   return(AutoFloatDividend);  }/**********************************************//* SetAutoFloatDividend: C access routine for *//*   the set-auto-float-dividend command.     *//**********************************************/globle BOOLEAN SetAutoFloatDividend(value)  int value;  {   int ov;   ov = AutoFloatDividend;   AutoFloatDividend = value;   return(ov);  }  /*****************************************//* IntegerFunction: CLIPS access routine *//*   for the integer function.           *//*****************************************/globle long int IntegerFunction()  {   DATA_OBJECT valstruct;    /*============================================*/   /* Check for the correct number of arguments. */   /*============================================*/      if (ArgCountCheck("integer",EXACTLY,1) == -1) return(0L);      /*================================================================*/   /* Check for the correct type of argument. Note that ArgTypeCheck */   /* will convert floats to integers when an integer is requested   */   /* (which is the purpose of the integer function).                */   /*================================================================*/      if (ArgTypeCheck("integer",1,INTEGER,&valstruct) == CLIPS_FALSE) return(0L);   /*===================================================*/   /* Return the numeric value converted to an integer. */   /*===================================================*/      return(ValueToLong(valstruct.value));  }/***************************************//* FloatFunction: CLIPS access routine *//*   for the float function.           *//***************************************/globle double FloatFunction()  {   DATA_OBJECT valstruct;      /*============================================*/   /* Check for the correct number of arguments. */   /*============================================*/   if (ArgCountCheck("float",EXACTLY,1) == -1) return(0.0);      /*================================================================*/   /* Check for the correct type of argument. Note that ArgTypeCheck */   /* will convert integers to floats when a float is requested      */   /* (which is the purpose of the float function).                  */   /*================================================================*/   if (ArgTypeCheck("float",1,FLOAT,&valstruct) == CLIPS_FALSE) return(0.0);   /*================================================*/   /* Return the numeric value converted to a float. */   /*================================================*/   return(ValueToDouble(valstruct.value));  }/*************************************//* AbsFunction: CLIPS access routine *//*   for the abs function.           *//*************************************/globle VOID AbsFunction(returnValue)  DATA_OBJECT_PTR returnValue;  {    /*============================================*/   /* Check for the correct number of arguments. */   /*============================================*/   if (ArgCountCheck("abs",EXACTLY,1) == -1)     {      returnValue->type = INTEGER;      returnValue->value = (VOID *) AddLong(0L);      return;     }   /*======================================*/   /* Check that the argument is a number. */   /*======================================*/      if (ArgTypeCheck("abs",1,INTEGER_OR_FLOAT,returnValue) == CLIPS_FALSE)     {      returnValue->type = INTEGER;      returnValue->value = (VOID *) AddLong(0L);      return;     }   /*==========================================*/   /* Return the absolute value of the number. */   /*==========================================*/      if (returnValue->type == INTEGER)     {      if (ValueToLong(returnValue->value) < 0L)        { returnValue->value = (VOID *) AddLong(- ValueToLong(returnValue->value)); }     }   else if (ValueToDouble(returnValue->value) < 0.0)     { returnValue->value = (VOID *) AddDouble(- ValueToDouble(returnValue->value)); }  }/*************************************//* MinFunction: CLIPS access routine *//*   for the min function.           *//*************************************/globle VOID MinFunction(returnValue)  DATA_OBJECT_PTR returnValue;  {   DATA_OBJECT argValue;   int numberOfArguments, i;   /*============================================*/   /* Check for the correct number of arguments. */   /*============================================*/      if ((numberOfArguments = ArgCountCheck("min",AT_LEAST,1)) == -1)     {      returnValue->type = INTEGER;      returnValue->value = (VOID *) AddLong(0L);      return;     }   /*============================================*/   /* Check that the first argument is a number. */   /*============================================*/      if (ArgTypeCheck("min",1,INTEGER_OR_FLOAT,returnValue) == CLIPS_FALSE)     {      returnValue->type = INTEGER;      returnValue->value = (VOID *) AddLong(0L);      return;     }        /*===========================================================*/   /* Loop through the remaining arguments, first checking each */   /* argument to see that it is a number, and then determining */   /* if the argument is less than the previous arguments and   */   /* is thus the minimum value.                                */   /*===========================================================*/   for (i = 2 ; i <= numberOfArguments ; i++)     {      if (ArgTypeCheck("min",i,INTEGER_OR_FLOAT,&argValue) == CLIPS_FALSE) return;      if (returnValue->type == INTEGER)        {         if (argValue.type == INTEGER)           {            if (ValueToLong(returnValue->value) > ValueToLong(argValue.value))              {               returnValue->type = argValue.type;               returnValue->value = argValue.value;              }           }         else           {            if ((double) ValueToLong(returnValue->value) >                         ValueToDouble(argValue.value))              {               returnValue->type = argValue.type;               returnValue->value = argValue.value;              }           }        }      else        {         if (argValue.type == INTEGER)           {            if (ValueToDouble(returnValue->value) >                (double) ValueToLong(argValue.value))              {               returnValue->type = argValue.type;               returnValue->value = argValue.value;              }           }         else           {            if (ValueToDouble(returnValue->value) > ValueToDouble(argValue.value))              {               returnValue->type = argValue.type;               returnValue->value = argValue.value;              }           }        }     }   return;  }/*************************************//* MaxFunction: CLIPS access routine *//*   for the max function.           *//*************************************/globle VOID MaxFunction(returnValue)  DATA_OBJECT_PTR returnValue;  {   DATA_OBJECT argValue;   int numberOfArguments, i;      /*============================================*/   /* Check for the correct number of arguments. */   /*============================================*/   if ((numberOfArguments = ArgCountCheck("max",AT_LEAST,1)) == -1)     {      returnValue->type = INTEGER;      returnValue->value = (VOID *) AddLong(0L);      return;     }   /*============================================*/   /* Check that the first argument is a number. */   /*============================================*/      if (ArgTypeCheck("max",1,INTEGER_OR_FLOAT,returnValue) == CLIPS_FALSE)     {      returnValue->type = INTEGER;      returnValue->value = (VOID *) AddLong(0L);      return;     }    /*===========================================================*/   /* Loop through the remaining arguments, first checking each */   /* argument to see that it is a number, and then determining */   /* if the argument is greater than the previous arguments    */   /* and is thus the maximum value.                            */   /*===========================================================*/      for (i = 2 ; i <= numberOfArguments ; i++)     {      if (ArgTypeCheck("max",i,INTEGER_OR_FLOAT,&argValue) == CLIPS_FALSE) return;      if (returnValue->type == INTEGER)        {         if (argValue.type == INTEGER)           {            if (ValueToLong(returnValue->value) < ValueToLong(argValue.value))              {               returnValue->type = argValue.type;               returnValue->value = argValue.value;              }           }         else           {            if ((double) ValueToLong(returnValue->value) <                         ValueToDouble(argValue.value))              {               returnValue->type = argValue.type;               returnValue->value = argValue.value;              }           }        }      else        {         if (argValue.type == INTEGER)           {            if (ValueToDouble(returnValue->value) <                (double) ValueToLong(argValue.value))              {               returnValue->type = argValue.type;               returnValue->value = argValue.value;              }           }         else           {            if (ValueToDouble(returnValue->value) < ValueToDouble(argValue.value))              {               returnValue->type = argValue.type;               returnValue->value = argValue.value;              }           }        }     }   return;  }

⌨️ 快捷键说明

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