NAME cplxerr complex error - error-handling functions in the C++ complex number math library SYNOPSIS #include <complex.h> class complex { ... }; static const complex complex_zero(0.0, 0.0); const int SING = ...; const int OVERFLOW = ...; const int UNDERFLOW = ...; class c_exception { public: c_exception(char *n, const complex& a1, const complex& a2=complex_zero); c_exception(unsigned char *n, const complex& a1, const complex& a2=complex_zero); friend int complex_error(c_exception&); // user may override private: int type; char *name; complex arg1, arg2; complex retval; }; DESCRIPTION Functions exp(), log(), log10(), sinh(), and cosh() invoke function complex_error() under the conditions described in cplxexp(3C++) and cplxtrig(3C++). If complex_error() returns zero, the return values and setting of errno will take place as described. In addition, a message describing the kind of error, the function which detected it, and the value causing the error will be written to cerr (see ios- tream documentation). If complex_error returns non-zero, errno is not set and no message is written. The default version of complex_error() just returns zero. The programmer may supply a replacement version of the func- tion to take any action deemed appropriate. The function takes one parameter of type ``reference to c_exception'', of which the function is a friend. class c_exception The class consists of the following fields: int type An integer describing the type of value, which has one of the values below, declared in the header as con- stants: SING argument singularity, such as divide by zero OVERFLOW overflow range error UNDERFLOW underflow range error char* name Points to a null-terminated string containing the name of the function where the error was detected. complex arg1, arg2 The arguments with which the function detecting the error was invoked. (Those functions which invoke complex_err() have only one argument, so arg2 will be irrelevant.) complex retval The default return value for the invoking function if complex_err() does not set some other value. A replacement version of complex_err() should return zero if setting errno and writing to cerr are desired, or return non-zero otherwise. The replacement could also change the retval field of its c_exception parameter if the default return value is not desired. EXAMPLE Suppose we want errno to be set, but we do not want to write anything to cerr (or anywhere else). Our replacement complex_err() will return non-zero, which will prevent a message from being written, but will also prevent errno from being set. Our function will have to set errno itself. #include <complex.h> int c_exception(c_exception& x) { switch( x.type ) { case UNDERFLOW: case OVERFLOW: errno = ERANGE; break; case SING: errno = EDOM; break; } return 1; } SEE ALSO cplx.intro(3C++), cartpol(3C++), cplxexp(3C++), cplxops(3C++), cplxtrig(3C++), intro(2), ios.intro(3C++), C++ Library Reference, Chapter 3, "The Complex Arithmetic Library."
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |