raze/source/common/thirdparty/math/mtherr.c

126 lines
3.7 KiB
C
Raw Normal View History

2020-04-11 21:50:43 +00:00
/* mtherr.c
*
* Library common error handling routine
*
*
*
* SYNOPSIS:
*
* char *fctnam;
* int code;
* int mtherr();
*
* mtherr( fctnam, code );
*
*
*
* DESCRIPTION:
*
* This routine may be called to report one of the following
* error conditions (in the include file mconf.h).
*
* Mnemonic Value Significance
*
* DOMAIN 1 argument domain error
* SING 2 function singularity
* OVERFLOW 3 overflow range error
* UNDERFLOW 4 underflow range error
* TLOSS 5 total loss of precision
* PLOSS 6 partial loss of precision
* EDOM 33 Unix domain error code
* ERANGE 34 Unix range error code
*
* The default version of the file prints the function name,
* passed to it by the pointer fctnam, followed by the
* error condition. The display is directed to the standard
* output device. The routine then returns to the calling
* program. Users may wish to modify the program to abort by
* calling exit() under severe error conditions such as domain
* errors.
*
* Since all error conditions pass control to this function,
* the display may be easily changed, eliminated, or directed
* to an error logging device.
*
* SEE ALSO:
*
* mconf.h
*
*/
/*
Cephes Math Library Release 2.0: April, 1987
Copyright 1984, 1987 by Stephen L. Moshier
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the <ORGANIZATION> nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Direct inquiries to 30 Frost Street, Cambridge, MA 02140
*/
#include <stdio.h>
#include "mconf.h"
int merror = 0;
/* Notice: the order of appearance of the following
* messages is bound to the error codes defined
* in mconf.h.
*/
static char *ermsg[7] = {
"unknown", /* error code 0 */
"domain", /* error code 1 */
"singularity", /* et seq. */
"overflow",
"underflow",
"total loss of precision",
"partial loss of precision"
};
- Modernise function declarations in Cephis C math to address ongoing GCC and Clang warnings. Examples: /home/mrichters/Repos/Raze/source/common/thirdparty/math/exp.c: In function ‘c_exp’: /home/mrichters/Repos/Raze/source/common/thirdparty/math/exp.c:171:48: warning: declaration of built-in function ‘floor’ without a prototype; expected ‘double(double)’ [-Wbuiltin-declaration-mismatch] 171 | double polevl(double, void *, int), floor(), ldexp(); | ^~~~~ /home/mrichters/Repos/Raze/source/common/thirdparty/math/exp.c:171:57: warning: declaration of built-in function ‘ldexp’ without a prototype; expected ‘double(double, int)’ [-Wbuiltin-declaration-mismatch] 171 | double polevl(double, void *, int), floor(), ldexp(); /home/mrichters/Repos/Raze/source/common/thirdparty/math/exp.c:200:16: warning: passing arguments to 'polevl' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype] px = x * polevl( xx, P, 2 ); ^ /home/mrichters/Repos/Raze/source/common/thirdparty/math/exp.c:201:17: warning: passing arguments to 'polevl' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype] x = px/( polevl( xx, Q, 3 ) - px ); ^ /home/mrichters/Repos/Raze/source/common/thirdparty/math/exp.c:167:8: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype] double c_exp(x) ^ 3 warnings generated.
2023-10-04 23:32:44 +00:00
int mtherr(char* name, int code)
2020-04-11 21:50:43 +00:00
{
/* Display string passed by calling program,
* which is supposed to be the name of the
* function in which the error occurred:
*/
printf( "\n%s ", name );
/* Set global error message word */
merror = code;
/* Display error message defined
* by the code argument.
*/
if( (code <= 0) || (code >= 7) )
code = 0;
printf( "%s error\n", ermsg[code] );
/* Return to calling
* program
*/
return( 0 );
}