/*------------------------------------------------------------------------
* 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
没有合适的资源?快使用搜索试试~ 我知道了~
Borland C++ 3.1 精简版 —— 学习uC/OS 的利器
共145个文件
h:75个
lib:25个
obj:21个
4星 · 超过85%的资源 需积分: 49 55 下载量 158 浏览量
2011-07-24
10:29:19
上传
评论
收藏 1.69MB RAR 举报
温馨提示
Borland C++ 3.1 精简版 —— 学习uC/OS 的利器。 用过的人都知道,哈哈~~
资源推荐
资源详情
资源评论
收起资源包目录
Borland C++ 3.1 精简版 —— 学习uC/OS 的利器 (145个子文件)
RULES.ASI 19KB
C0.ASM 26KB
C0D.ASM 14KB
C0W.ASM 13KB
BUILD-C0.BAT 2KB
MATHERR.C 6KB
FILES.C 1KB
FILES2.C 990B
test.c 290B
TURBOC.CFG 30B
TLINK.CFG 13B
TOUCH.COM 5KB
BC30RTL.DLL 140KB
DPMIMEM.DLL 24KB
BCC.EXE 656KB
TLINK.EXE 147KB
TASM.EXE 126KB
MAKE.EXE 88KB
TLIB.EXE 37KB
DPMILOAD.EXE 22KB
EXEMAP.EXE 17KB
WINDOWS.H 155KB
WIN30.H 117KB
MMSYSTEM.H 78KB
WINDOWSX.H 62KB
IOSTREAM.H 29KB
PENWIN.H 26KB
OLE.H 25KB
DOS.H 18KB
DDEML.H 16KB
TOOLHELP.H 14KB
GRAPHICS.H 14KB
COMMDLG.H 12KB
PRINT.H 11KB
CUSTCNTL.H 10KB
VER.H 10KB
BCD.H 9KB
STDIO.H 9KB
STRING.H 8KB
STDLIB.H 8KB
COMPLEX.H 8KB
FSTREAM.H 7KB
IOMANIP.H 7KB
CPL.H 6KB
DLGS.H 6KB
MATH.H 5KB
FLOAT.H 5KB
DDE.H 5KB
CONSTREA.H 5KB
BIOS.H 5KB
CONIO.H 5KB
IO.H 4KB
ERRNO.H 4KB
LZEXPAND.H 4KB
STRSTREA.H 3KB
MEM.H 3KB
WFEXT.H 3KB
BWCC.H 3KB
SHELLAPI.H 3KB
PENWOEM.H 3KB
ALLOC.H 3KB
PROCESS.H 2KB
DIR.H 2KB
_DEFS.H 2KB
CDERR.H 2KB
TIME.H 2KB
CTYPE.H 2KB
STRESS.H 2KB
COLORDLG.H 2KB
GENERIC.H 2KB
STDIOSTR.H 2KB
STAT.H 1KB
FCNTL.H 1KB
MALLOC.H 1KB
DIRENT.H 1KB
SEARCH.H 1KB
VALUES.H 1KB
LOCALE.H 1KB
SIGNAL.H 1KB
LIMITS.H 978B
STDARG.H 895B
SETJMP.H 888B
ASSERT.H 812B
VARARGS.H 797B
STDDEF.H 726B
UTIME.H 631B
NEW.H 627B
TIMEB.H 581B
SHARE.H 527B
LOCKING.H 499B
DIRECT.H 489B
_NULL.H 287B
_NFILE.H 211B
TYPES.H 204B
MEMORY.H 158B
DRIVINIT.H 57B
WINDOWS.INC 65KB
MMSYSTEM.INC 59KB
TOOLHELP.INC 9KB
CWL.LIB 266KB
共 145 条
- 1
- 2
卧龙茗舌
- 粉丝: 0
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页