From f95a4a932476be2ba99e2fd081e8d2bc6ea12813 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Fri, 15 Dec 2017 09:38:53 -0500 Subject: Import newlib and create makefile --- newlib/libm/common/s_matherr.c | 123 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 newlib/libm/common/s_matherr.c (limited to 'newlib/libm/common/s_matherr.c') diff --git a/newlib/libm/common/s_matherr.c b/newlib/libm/common/s_matherr.c new file mode 100644 index 0000000..58e2428 --- /dev/null +++ b/newlib/libm/common/s_matherr.c @@ -0,0 +1,123 @@ + +/* @(#)s_matherr.c 5.1 93/09/24 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + +FUNCTION + <>---modifiable math error handler + +INDEX + matherr + +ANSI_SYNOPSIS + #include + int matherr(struct exception *<[e]>); + +TRAD_SYNOPSIS + #include + int matherr(*<[e]>) + struct exception *<[e]>; + +DESCRIPTION +<> is called whenever a math library function generates an error. +You can replace <> by your own subroutine to customize +error treatment. The customized <> must return 0 if +it fails to resolve the error, and non-zero if the error is resolved. + +When <> returns a nonzero value, no error message is printed +and the value of <> is not modified. You can accomplish either +or both of these things in your own <> using the information +passed in the structure <<*<[e]>>>. + +This is the <> structure (defined in `<>'): +. struct exception { +. int type; +. char *name; +. double arg1, arg2, retval; +. int err; +. }; + +The members of the exception structure have the following meanings: +o+ +o type +The type of mathematical error that occured; macros encoding error +types are also defined in `<>'. + +o name +a pointer to a null-terminated string holding the +name of the math library function where the error occurred. + +o arg1, arg2 +The arguments which caused the error. + +o retval +The error return value (what the calling function will return). + +o err +If set to be non-zero, this is the new value assigned to <>. +o- + +The error types defined in `<>' represent possible mathematical +errors as follows: + +o+ +o DOMAIN +An argument was not in the domain of the function; e.g. <>. + +o SING +The requested calculation would result in a singularity; e.g. <> + +o OVERFLOW +A calculation would produce a result too large to represent; e.g. +<>. + +o UNDERFLOW +A calculation would produce a result too small to represent; e.g. +<>. + +o TLOSS +Total loss of precision. The result would have no significant digits; +e.g. <>. + +o PLOSS +Partial loss of precision. +o- + + +RETURNS +The library definition for <> returns <<0>> in all cases. + +You can change the calling function's result from a customized <> +by modifying <retval>>, which propagates backs to the caller. + +If <> returns <<0>> (indicating that it was not able to resolve +the error) the caller sets <> to an appropriate value, and prints +an error message. + +PORTABILITY +<> is not ANSI C. +*/ + +#include "fdlibm.h" + +#ifdef __STDC__ + int matherr(struct exception *x) +#else + int matherr(x) + struct exception *x; +#endif +{ + int n=0; + if(x->arg1!=x->arg1) return 0; + return n; +} -- cgit v1.2.3