/*------------------------------------------------------------------------
* filename - matherr.c
*
* function(s)
* matherr - user-modifiable math error handler
*-----------------------------------------------------------------------*/
/*
* C/C++ Run Time Library - Version 5.0
*
* Copyright (c) 1987, 1992 by Borland International
* All Rights Reserved.
*
*/
#include <math.h>
#ifdef _Windows
#include <_win.h>
#endif
#ifdef UNIX_matherr
#include <stdio.h>
#include <process.h>
char *whyS [] =
{
"argument domain error",
"argument singularity ",
"overflow range error ",
"underflow range error",
"total loss of significance",
"partial loss of significance"
};
/*------------------------------------------------------------------------*
Name matherr - user-modifiable math error handler
Usage #include <math.h>
int matherr(struct exception *e);
Prototype in math.h
Description When exceptions are detected in the math library then a
call is made to _matherr() with all the available
information.
That function does very little, except to map the exception
"why" into either ERANGE or EDOMAIN in errno. Its main
purpose is to act as a focal point for changes in error
handling.
For example, if you were writing a spreadsheet you might
replace this function with one which pops up an error
window explaining something like:
"log (-2.0) caused domain error, in cell J7"
and then longjmp() to a reset state in the spreadsheet and
await the next command from the user.
The default version of Turbo C's matherr routine masks
underflow and precision errors; others errors are considered
fatal. It serves as a hook that you can replace when
writing your own math error handling routine.
The rationale for masking underflow and precision errors
is that these are not errors according to the ANSI C spec.
Consequently, you will get
exp(-1000) = 0
sin(1e100) = NAN
without any error or warning, even though there is a total
loss of precision in both cases. You can trap these errors
by modifying matherr.
The possible errors are
DOMAIN, SING, OVERFLOW, UNDERFLOW, TLOSS, PLOSS
and listed in <math.h>. As explained above, UNDERFLOW and
TLOSS are masked by the default matherr. PLOSS is not
supported by TC and is not generated by any library functions.
The remaining errors, DOMAIN, SING, and OVERFLOW, are fatal
with the default matherr.
You can modify matherr to be a custom error handling
routine (such as one that catches and resolves certain type
of errors); the modified matherr should return 0 if it
failed to resolve the error, or non-zero if the error was
resolved. When matherr returns non-zero, no error message
is printed, and errno is not changed.
The important thing is that we don't know what error
handling you want, but you are assured that all errors will
arrive at matherr() with all the information you need to
design a custom format.
We do not ship as standard the function named matherr()
which may be familiar to UNIX users, since the ANSI x3j11
draft specifies an incompatible style. This version is as
close as we could get without breaking the ANSI rules. You
can, however, convert this version to the UNIX style if you
prefer. The necessary code is included but switched off.
Return value The default return value for matherr is simply 0.
matherr can also modify e->retval, which propagates through
_matherr back to the original caller.
When matherr returns 0, (indicating that it was not able to
resolve the error) _matherr sets errno and prints an error
message.
When matherr returns non-zero, (indicating that it was able
to resolve the error) errno is not set and no messages are
printed.
*-------------------------------------------------------------------------*/
int _FARFUNC matherr (struct exception *e)
{
#ifdef _Windows
char errMsg[ 80 ];
sprintf (errMsg,
"%s (%8g,%8g): %s\n", e->name, e->arg1, e->arg2, whyS [e->type - 1]);
_errorExitBox( errMsg, 1 );
#else
fprintf (stderr,
"%s (%8g,%8g): %s\n", e->name, e->arg1, e->arg2, whyS [e->type - 1]);
exit (1);
#endif
}
#else
int _FARFUNC matherr(struct exception *e)
{
if (e->type == UNDERFLOW)
{
/* flush underflow to 0 */
e->retval = 0;
return 1;
}
if (e->type == TLOSS)
{
/* total loss of precision, but ignore the problem */
return 1;
}
/* all other errors are fatal */
return 0;
}
#endif
ucosII.zip_constrea.h 什么_ucosii
版权申诉
3 浏览量
2022-09-19
14:49:09
上传
评论
收藏 1.86MB ZIP 举报
局外狗
- 粉丝: 64
- 资源: 1万+
最新资源
- 基于matlab实现麦克风阵列的声源定位,四元十字阵的matlab仿真.rar
- 基于matlab实现麦克风阵列的声源定位一维music算法源代码.rar
- 基于matlab实现脉动风速模拟程序Tubsim计算结果可视化程序.rar
- 基于matlab实现脉动风速时程模拟,谐波合成法,用于各种分析方式的试验模拟.rar
- 基于matlab实现蒙特卡洛算法的仿真源代码 介绍了蒙特卡洛仿真的基本思想 并附带了一些具体例子.rar
- 代码.zip代码.zip代码数据分析代码.zip代码.zip代码数据分析
- 基于matlab实现模拟钢筋混凝土本构模型,可以作钢筋混凝土本构曲线.rar
- 基于matlab实现模拟退火GUI演示,利用模拟退火算法求全局最大值最小值.rar
- 基于matlab实现模拟退火程序 f(x,y) = 5sin(xy) + x^2 + y^2的最小值
- 基于matlab实现模拟退火算法计算函数最小值以及SVM参数寻优.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈