|  | 
|  | 1 | +/**************************************************************** | 
|  | 2 | +Copyright (C) Lucent Technologies 1997 | 
|  | 3 | +All Rights Reserved | 
|  | 4 | +
 | 
|  | 5 | +Permission to use, copy, modify, and distribute this software and | 
|  | 6 | +its documentation for any purpose and without fee is hereby | 
|  | 7 | +granted, provided that the above copyright notice appear in all | 
|  | 8 | +copies and that both that the copyright notice and this | 
|  | 9 | +permission notice and warranty disclaimer appear in supporting | 
|  | 10 | +documentation, and that the name Lucent Technologies or any of | 
|  | 11 | +its entities not be used in advertising or publicity pertaining | 
|  | 12 | +to distribution of the software without specific, written prior | 
|  | 13 | +permission. | 
|  | 14 | +
 | 
|  | 15 | +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | 
|  | 16 | +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. | 
|  | 17 | +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY | 
|  | 18 | +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 
|  | 19 | +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER | 
|  | 20 | +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, | 
|  | 21 | +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF | 
|  | 22 | +THIS SOFTWARE. | 
|  | 23 | +****************************************************************/ | 
|  | 24 | + | 
|  | 25 | +#pragma STDC FENV_ACCESS ON | 
|  | 26 | + | 
|  | 27 | +#include <errno.h> | 
|  | 28 | +#include <fenv.h> | 
|  | 29 | +#include <math.h> | 
|  | 30 | +#include <stdio.h> | 
|  | 31 | + | 
|  | 32 | +#include "awk.h" | 
|  | 33 | + | 
|  | 34 | +#ifndef FE_DIVBYZERO | 
|  | 35 | +#define FE_DIVBYZERO 0 | 
|  | 36 | +#endif | 
|  | 37 | + | 
|  | 38 | +#ifndef FE_INVALID | 
|  | 39 | +#define FE_INVALID 0 | 
|  | 40 | +#endif | 
|  | 41 | + | 
|  | 42 | +#ifndef FE_OVERFLOW | 
|  | 43 | +#define FE_OVERFLOW 0 | 
|  | 44 | +#endif | 
|  | 45 | + | 
|  | 46 | +#ifndef FE_UNDERFLOW | 
|  | 47 | +#define FE_UNDERFLOW 0 | 
|  | 48 | +#endif | 
|  | 49 | + | 
|  | 50 | +#define errclear()							\ | 
|  | 51 | +	do {								\ | 
|  | 52 | +		errno = 0;						\ | 
|  | 53 | +		feclearexcept(FE_ALL_EXCEPT);				\ | 
|  | 54 | +	} while (0) | 
|  | 55 | + | 
|  | 56 | +static double errcheck(double x, const char *s) | 
|  | 57 | +{ | 
|  | 58 | +	if (errno == EDOM || fetestexcept(FE_INVALID)) { | 
|  | 59 | +		errno = 0; | 
|  | 60 | +		WARNING("%s argument out of domain", s); | 
|  | 61 | +		x = 1; | 
|  | 62 | +	} else if (errno == ERANGE || fetestexcept(FE_DIVBYZERO | FE_OVERFLOW | | 
|  | 63 | +	    FE_UNDERFLOW)) { | 
|  | 64 | +		errno = 0; | 
|  | 65 | +		WARNING("%s result out of range", s); | 
|  | 66 | +		x = 1; | 
|  | 67 | +	} | 
|  | 68 | + | 
|  | 69 | +	return x; | 
|  | 70 | +} | 
|  | 71 | + | 
|  | 72 | +double exp_errcheck(double x) | 
|  | 73 | +{ | 
|  | 74 | +	errclear(); | 
|  | 75 | +	return errcheck(exp(x), "exp"); | 
|  | 76 | +} | 
|  | 77 | + | 
|  | 78 | +double log_errcheck(double x) | 
|  | 79 | +{ | 
|  | 80 | +	errclear(); | 
|  | 81 | +	return errcheck(log(x), "log"); | 
|  | 82 | +} | 
|  | 83 | + | 
|  | 84 | +double pow_errcheck(double x, double y) | 
|  | 85 | +{ | 
|  | 86 | +	errclear(); | 
|  | 87 | +	return errcheck(pow(x, y), "pow"); | 
|  | 88 | +} | 
|  | 89 | + | 
|  | 90 | +double sqrt_errcheck(double x) | 
|  | 91 | +{ | 
|  | 92 | +	errclear(); | 
|  | 93 | +	return errcheck(sqrt(x), "sqrt"); | 
|  | 94 | +} | 
0 commit comments