_matherr

수학 오류를 처리합니다.

구문

int _matherr(struct _exception *except);

매개 변수

except
오류 정보를 포함하는 구조에 대한 포인터입니다.

반환 값

_matherr 는 0을 반환하여 오류를 나타내거나 성공을 나타내는 0이 아닌 값을 반환합니다.

  • 0을 반환하면 _matherr 오류 메시지가 표시될 수 있으며 errno 적절한 오류 값으로 설정됩니다.
  • 0이 아닌 값을 반환하는 경우 _matherr 오류 메시지가 표시되지 않고 errno 변경되지 기본.

반환 코드에 대한 자세한 내용은 , , 및 를 참조하세요errno._sys_nerr_sys_errlist_doserrno

설명

이 함수는 _matherr 수학 라이브러리의 부동 소수점 함수에 의해 생성된 오류를 처리합니다. 이러한 함수는 오류가 검색될 때 호출 _matherr 됩니다. 이 상호 작용은 컴파일러의 부동 소수점 모드 또는 부동 소수점 제어 단어영향을 받지 않습니다. _matherr 라이브러리 함수이므로 수학 내장 함수는 이를 호출하지 않습니다.

특별한 오류 처리의 경우 다른 정의를 _matherr제공할 수 있습니다. 동적으로 연결된 버전의 CRT(C 런타임 라이브러리)를 사용하는 경우 클라이언트 실행 파일의 기본 _matherr 루틴을 사용자 정의 버전으로 바꿀 수 있습니다. 그러나 CRT DLL의 DLL 클라이언트에서 기본 _matherr 루틴을 바꿀 수는 없습니다.

수학 루틴 _matherr 에서 오류가 발생하면 형식 구조(정의된)에 <math.h>대한 포인터 _exception 를 인수로 사용하여 호출됩니다. 구조체에는 _exception 다음 요소가 포함됩니다.

struct _exception
{
    int    type;   // exception type - see below
    char*  name;   // name of function where error occurred
    double arg1;   // first argument to function
    double arg2;   // second argument (if any) to function
    double retval; // value to be returned by function
};

멤버는 type 수학 오류의 유형을 지정합니다. 다음 값 중 하나로, 다음 값에 정의되어 있습니다.<math.h>

매크로 설명
_DOMAIN 인수 do기본 오류
_SING 인수 특이점
_OVERFLOW 오버플로 범위 오류
_PLOSS 중요도 부분 손실
_TLOSS 총 유의 손실
_UNDERFLOW 결과가 너무 작아 나타낼 수 없습니다. (이 조건은 현재 지원되지 않습니다.)

구조체 멤버 name 는 오류를 발생시킨 함수의 이름을 포함하는 null로 끝나는 문자열에 대한 포인터입니다. 구조체 멤버 arg1 이며 arg2 오류를 발생시킨 값을 지정합니다. 인수가 하나만 지정되면 에 저장됩니다 arg1.

지정된 오류의 기본 반환 값은 .입니다 retval. 반환 값을 변경하는 경우 오류가 실제로 발생했는지 여부를 해당 값이 지정해야 합니다.

요구 사항

루틴에서 반환된 값 필수 헤더
_matherr <math.h>

호환성에 대한 자세한 내용은 호환성을 참조하세요.

예시

/* crt_matherr.c
* Illustrates writing an error routine for math
* functions. 
* The error handling function must be named _matherr
*/

#include <math.h>
#include <string.h>
#include <stdio.h>

int main()
{
    /* Do several math operations that cause errors. The _matherr
     * routine handles _DOMAIN errors, but lets the system handle
     * other errors normally.
     */
    printf( "log( -2.0 ) = %e\n", log( -2.0 ) );
    printf( "log10( -5.0 ) = %e\n", log10( -5.0 ) );
    printf( "log( 0.0 ) = %e\n", log( 0.0 ) );
}

/* Handle several math errors caused by passing a negative argument
* to log or log10 (_DOMAIN errors). When this happens, _matherr
* returns the natural or base-10 logarithm of the absolute value
* of the argument and suppresses the usual error message.
*/
int _matherr(struct _exception *except)
{
    /* Handle _DOMAIN errors for log or log10. */
    if (except->type == _DOMAIN)
    {
        if (strcmp(except->name, "log") == 0)
        {
            except->retval = log(-(except->arg1));
            printf("Special: using absolute value: %s: _DOMAIN "
                     "error\n", except->name);
            return 1;
        }
        else if (strcmp(except->name, "log10") == 0)
        {
            except->retval = log10(-(except->arg1));
            printf("Special: using absolute value: %s: _DOMAIN "
                     "error\n", except->name);
            return 1;
        }
    }
    printf("Normal: ");
    return 0;    /* Else use the default actions */
}
Special: using absolute value: log: _DOMAIN error
log( -2.0 ) = 6.931472e-01
Special: using absolute value: log10: _DOMAIN error
log10( -5.0 ) = 6.989700e-01
Normal: log( 0.0 ) = -inf

참고 항목

수학 및 부동 소수점 지원