📄 emathfun.c
字号:
/**************************************/
/* CschFunction: H/L access routine */
/* for the csch function. */
/**************************************/
globle double CschFunction(
void *theEnv)
{
double num;
if (SingleNumberCheck(theEnv,"csch",&num) == FALSE) return(0.0);
if (num == 0.0)
{
SingularityErrorMessage(theEnv,"csch");
return(0.0);
}
else if (TestProximity(num,1e-25) == TRUE)
{
ArgumentOverflowErrorMessage(theEnv,"csch");
return(0.0);
}
return(1.0 / sinh(num));
}
/**************************************/
/* CothFunction: H/L access routine */
/* for the coth function. */
/**************************************/
globle double CothFunction(
void *theEnv)
{
double num;
if (SingleNumberCheck(theEnv,"coth",&num) == FALSE) return(0.0);
if (num == 0.0)
{
SingularityErrorMessage(theEnv,"coth");
return(0.0);
}
else if (TestProximity(num,1e-25) == TRUE)
{
ArgumentOverflowErrorMessage(theEnv,"coth");
return(0.0);
}
return(1.0 / tanh(num));
}
/***************************************/
/* AcoshFunction: H/L access routine */
/* for the acosh function. */
/***************************************/
globle double AcoshFunction(
void *theEnv)
{
double num;
if (SingleNumberCheck(theEnv,"acosh",&num) == FALSE) return(0.0);
if (num < 1.0)
{
DomainErrorMessage(theEnv,"acosh");
return(0.0);
}
return(genacosh(num));
}
/***************************************/
/* AsinhFunction: H/L access routine */
/* for the asinh function. */
/***************************************/
globle double AsinhFunction(
void *theEnv)
{
double num;
if (SingleNumberCheck(theEnv,"asinh",&num) == FALSE) return(0.0);
return(genasinh(num));
}
/***************************************/
/* AtanhFunction: H/L access routine */
/* for the atanh function. */
/***************************************/
globle double AtanhFunction(
void *theEnv)
{
double num;
if (SingleNumberCheck(theEnv,"atanh",&num) == FALSE) return(0.0);
if ((num >= 1.0) || (num <= -1.0))
{
DomainErrorMessage(theEnv,"atanh");
return(0.0);
}
return(genatanh(num));
}
/***************************************/
/* AsechFunction: H/L access routine */
/* for the asech function. */
/***************************************/
globle double AsechFunction(
void *theEnv)
{
double num;
if (SingleNumberCheck(theEnv,"asech",&num) == FALSE) return(0.0);
if ((num > 1.0) || (num <= 0.0))
{
DomainErrorMessage(theEnv,"asech");
return(0.0);
}
return(genasech(num));
}
/***************************************/
/* AcschFunction: H/L access routine */
/* for the acsch function. */
/***************************************/
globle double AcschFunction(
void *theEnv)
{
double num;
if (SingleNumberCheck(theEnv,"acsch",&num) == FALSE) return(0.0);
if (num == 0.0)
{
DomainErrorMessage(theEnv,"acsch");
return(0.0);
}
return(genacsch(num));
}
/***************************************/
/* AcothFunction: H/L access routine */
/* for the acoth function. */
/***************************************/
globle double AcothFunction(
void *theEnv)
{
double num;
if (SingleNumberCheck(theEnv,"acoth",&num) == FALSE) return(0.0);
if ((num <= 1.0) && (num >= -1.0))
{
DomainErrorMessage(theEnv,"acoth");
return(0.0);
}
return(genacoth(num));
}
/*************************************/
/* ExpFunction: H/L access routine */
/* for the exp function. */
/*************************************/
globle double ExpFunction(
void *theEnv)
{
double num;
if (SingleNumberCheck(theEnv,"exp",&num) == FALSE) return(0.0);
return(exp(num));
}
/*************************************/
/* LogFunction: H/L access routine */
/* for the log function. */
/*************************************/
globle double LogFunction(
void *theEnv)
{
double num;
if (SingleNumberCheck(theEnv,"log",&num) == FALSE) return(0.0);
if (num < 0.0)
{
DomainErrorMessage(theEnv,"log");
return(0.0);
}
else if (num == 0.0)
{
ArgumentOverflowErrorMessage(theEnv,"log");
return(0.0);
}
return(log(num));
}
/***************************************/
/* Log10Function: H/L access routine */
/* for the log10 function. */
/***************************************/
globle double Log10Function(
void *theEnv)
{
double num;
if (SingleNumberCheck(theEnv,"log10",&num) == FALSE) return(0.0);
if (num < 0.0)
{
DomainErrorMessage(theEnv,"log10");
return(0.0);
}
else if (num == 0.0)
{
ArgumentOverflowErrorMessage(theEnv,"log10");
return(0.0);
}
return(log10(num));
}
/**************************************/
/* SqrtFunction: H/L access routine */
/* for the sqrt function. */
/**************************************/
globle double SqrtFunction(
void *theEnv)
{
double num;
if (SingleNumberCheck(theEnv,"sqrt",&num) == FALSE) return(0.0);
if (num < 0.00000)
{
DomainErrorMessage(theEnv,"sqrt");
return(0.0);
}
return(sqrt(num));
}
/*************************************/
/* PowFunction: H/L access routine */
/* for the pow function. */
/*************************************/
globle double PowFunction(
void *theEnv)
{
DATA_OBJECT value1, value2;
if (EnvArgCountCheck(theEnv,"**",EXACTLY,2) == -1) return(0.0);
if (EnvArgTypeCheck(theEnv,"**",1,FLOAT,&value1) == FALSE) return(0.0);
if (EnvArgTypeCheck(theEnv,"**",2,FLOAT,&value2) == FALSE) return(0.0);
if (((DOToDouble(value1) == 0.0) &&
(DOToDouble(value2) <= 0.0)) ||
((DOToDouble(value1) < 0.0) &&
(dtrunc((double) DOToDouble(value2)) != DOToDouble(value2))))
{
DomainErrorMessage(theEnv,"**");
SetHaltExecution(theEnv,TRUE);
SetEvaluationError(theEnv,TRUE);
return(0.0);
}
return (pow(DOToDouble(value1),DOToDouble(value2)));
}
/*************************************/
/* ModFunction: H/L access routine */
/* for the mod function. */
/*************************************/
globle void ModFunction(
void *theEnv,
DATA_OBJECT_PTR result)
{
DATA_OBJECT item1, item2;
double fnum1, fnum2;
long lnum1, lnum2;
if (EnvArgCountCheck(theEnv,"mod",EXACTLY,2) == -1)
{
result->type = INTEGER;
result->value = (void *) EnvAddLong(theEnv,0L);
return;
}
if (EnvArgTypeCheck(theEnv,"mod",1,INTEGER_OR_FLOAT,&item1) == FALSE)
{
result->type = INTEGER;
result->value = (void *) EnvAddLong(theEnv,0L);
return;
}
if (EnvArgTypeCheck(theEnv,"mod",2,INTEGER_OR_FLOAT,&item2) == FALSE)
{
result->type = INTEGER;
result->value = (void *) EnvAddLong(theEnv,0L);
return;
}
if (((item2.type == INTEGER) ? (ValueToLong(item2.value) == 0L) : FALSE) ||
((item2.type == FLOAT) ? ValueToDouble(item2.value) == 0.0 : FALSE))
{
DivideByZeroErrorMessage(theEnv,"mod");
SetEvaluationError(theEnv,TRUE);
result->type = INTEGER;
result->value = (void *) EnvAddLong(theEnv,0L);
return;
}
if ((item1.type == FLOAT) || (item2.type == FLOAT))
{
fnum1 = CoerceToDouble(item1.type,item1.value);
fnum2 = CoerceToDouble(item2.type,item2.value);
result->type = FLOAT;
result->value = (void *) EnvAddDouble(theEnv,fnum1 - (dtrunc(fnum1 / fnum2) * fnum2));
}
else
{
lnum1 = DOToLong(item1);
lnum2 = DOToLong(item2);
result->type = INTEGER;
result->value = (void *) EnvAddLong(theEnv,lnum1 - (lnum1 / lnum2) * lnum2);
}
}
/************************************/
/* PiFunction: H/L access routine */
/* for the pi function. */
/************************************/
globle double PiFunction(
void *theEnv)
{
if (EnvArgCountCheck(theEnv,"pi",EXACTLY,0) == -1) return(acos(-1.0));
return(acos(-1.0));
}
/****************************************/
/* DegRadFunction: H/L access routine */
/* for the deg-rad function. */
/****************************************/
globle double DegRadFunction(
void *theEnv)
{
double num;
if (SingleNumberCheck(theEnv,"deg-rad",&num) == FALSE) return(0.0);
return(num * PI / 180.0);
}
/****************************************/
/* RadDegFunction: H/L access routine */
/* for the rad-deg function. */
/****************************************/
globle double RadDegFunction(
void *theEnv)
{
double num;
if (SingleNumberCheck(theEnv,"rad-deg",&num) == FALSE) return(0.0);
return(num * 180.0 / PI);
}
/*****************************************/
/* DegGradFunction: H/L access routine */
/* for the deg-grad function. */
/*****************************************/
globle double DegGradFunction(
void *theEnv)
{
double num;
if (SingleNumberCheck(theEnv,"deg-grad",&num) == FALSE) return(0.0);
return(num / 0.9);
}
/*****************************************/
/* GradDegFunction: H/L access routine */
/* for the grad-deg function. */
/*****************************************/
globle double GradDegFunction(
void *theEnv)
{
double num;
if (SingleNumberCheck(theEnv,"grad-deg",&num) == FALSE) return(0.0);
return(num * 0.9);
}
/***************************************/
/* RoundFunction: H/L access routine */
/* for the round function. */
/***************************************/
globle long int RoundFunction(
void *theEnv)
{
DATA_OBJECT result;
if (EnvArgCountCheck(theEnv,"round",EXACTLY,1) == -1)
{ return(0L); }
if (EnvArgTypeCheck(theEnv,"round",1,INTEGER_OR_FLOAT,&result) == FALSE)
{ return(0L); }
if (result.type == INTEGER)
{ return(ValueToLong(result.value)); }
else
{ return((long) ceil(ValueToDouble(result.value) - 0.5)); }
}
/*******************************************/
/* genacsch: Generic routine for computing */
/* the hyperbolic arccosine. */
/*******************************************/
static double genacosh(
double num)
{
return(log(num + sqrt(num * num - 1.0)));
}
/*******************************************/
/* genacsch: Generic routine for computing */
/* the hyperbolic arcsine. */
/*******************************************/
static double genasinh(
double num)
{
return(log(num + sqrt(num * num + 1.0)));
}
/*******************************************/
/* genatanh: Generic routine for computing */
/* the hyperbolic arctangent. */
/*******************************************/
static double genatanh(
double num)
{
return((0.5) * log((1.0 + num) / (1.0 - num)));
}
/*******************************************/
/* genacsch: Generic routine for computing */
/* the hyperbolic arcsecant. */
/*******************************************/
static double genasech(
double num)
{
return(log(1.0 / num + sqrt(1.0 / (num * num) - 1.0)));
}
/*******************************************/
/* genacsch: Generic routine for computing */
/* the hyperbolic arccosecant. */
/*******************************************/
static double genacsch(
double num)
{
return(log(1.0 / num + sqrt(1.0 / (num * num) + 1.0)));
}
/*******************************************/
/* genacoth: Generic routine for computing */
/* the hyperbolic arccotangent. */
/*******************************************/
static double genacoth(
double num)
{
return((0.5) * log((num + 1.0) / (num - 1.0)));
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -