1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
/**
* \file mathFuncs.h
* \brief Mathematical functions.
* \copyright Copyright (C) 2006-2022 Ralf Hoppe <ralf.hoppe@dfcgen.de>
*/
#ifndef MATHFUNCS_H
#define MATHFUNCS_H
/* INCLUDE FILES **************************************************************/
#include "base.h" /* includes config.h (include before math.h) */
#include <math.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_sf.h> /* all special functions */
#include <gsl/gsl_errno.h>
#ifdef __cplusplus
extern "C" {
#endif
/* GLOBAL TYPE DECLARATIONS ***************************************************/
/** Decimal normalized double value. The original value is determined by
* \f$m 10^e\f$.
*/
typedef struct
{
double mantissa; /**< mantissa m */
double exponent; /**< exponent e */
} MATH_NORMDBL;
/* GLOBAL CONSTANT DECLARATIONS ***********************************************/
/* GLOBAL VARIABLE DECLARATIONS ***********************************************/
/* GLOBAL MACRO DEFINITIONS ***************************************************/
/** This macro swaps two integers (inline).
*/
#define MATH_SWAP_INT(int1, int2) \
{ \
(int1) ^= (int2); \
(int2) ^= (int1); \
(int1) ^= (int2); \
}
#ifdef HAVE_HYPOT
#define HYPOT(x, y) hypot ((x), (y))
#else
#define HYPOT(x, y) gsl_hypot ((x), (y))
#endif
#ifdef HAVE_POW10 /* pow10() exists? */
#define POW10(x) pow10(x)
#else
#ifdef HAVE_EXP10
#define POW10(x) exp10(x) /**< 10 raised to \p x, means \f$y=10^{x}\f$ */
#else
#define POW10(x) pow(10, (x)) /* fallback to (slow) generic function */
#endif /* HAVE_EXP10 */
#endif /* HAVE_POW10 */
#ifndef HAVE_TRUNC
#define trunc(x) ((GSL_SIGN(x) > 0) ? floor(x) : ceil(x))
#endif
#ifndef HAVE_ROUND
#define round(x) floor((x) + 0.5) /* fallback to (slow) generic */
#endif
/* EXPORTED FUNCTIONS *********************************************************/
/* FUNCTION *******************************************************************/
/** Calculates a normalized value consisting of (decimal) mantissa and exponent.
*
* \param val Value to be converted.
*
* \return Normalized value.
******************************************************************************/
MATH_NORMDBL mathNorm10(double val);
/* FUNCTION *******************************************************************/
/** Denormalizes a decimal value from its mantissa and exponent.
*
* \param val Normalized value to be converted.
*
* \return Denormalized value.
******************************************************************************/
double mathDenorm10(MATH_NORMDBL val);
/* FUNCTION *******************************************************************/
/** Rectangle function
\f[
y = \begin{cases} 0, & \mbox{if} \;\; x<0 \\
0, & \mbox{if} \;\; x>1 \\
1, & \mbox{else} \end{cases}
\f]
*
* \param x Argument \f$x\f$.
*
* \return Result \f$y\f$.
******************************************************************************/
double mathFuncRectangle (double x);
/* FUNCTION *******************************************************************/
/** \e Hamming window function
\f[
y = \begin{cases} 0, & \mbox{if} \;\; x<0 \\
0, & \mbox{if} \;\; x>1 \\
0.54-0.46 \cos(2\pi x), & \mbox{else} \end{cases}
\f]
*
* \param x Argument \f$x\f$.
*
* \return Result \f$y\f$.
******************************************************************************/
double mathFuncHamming (double x);
/* FUNCTION *******************************************************************/
/** \e van \e Hann window function
\f[
y = \begin{cases} 0, & \mbox{if} \;\; x<0 \\
0, & \mbox{if} \;\; x>1 \\
\frac{1}{2}\,[1-\cos(2\pi x)], & \mbox{else} \end{cases}
\f]
*
* \param x Argument \f$x\f$.
*
* \return Result \f$y\f$.
******************************************************************************/
double mathFuncVanHann (double x);
/* FUNCTION *******************************************************************/
/** \e Blackman window function
\f[
y = \begin{cases} 0, & \mbox{if} \;\; x<0 \\
0, & \mbox{if} \;\; x>1 \\
0.42-0.5\cos(2\pi x)+0.08\cos(4\pi x), & \mbox{else}
\end{cases}
\f]
*
* \param x Argument \f$x\f$.
*
* \return Result \f$y\f$.
******************************************************************************/
double mathFuncBlackman (double x);
/* FUNCTION *******************************************************************/
/** \e Kaiser window function
\f[
y = \begin{cases} 0, & \mbox{if} \;\; x<0 \\
0, & \mbox{if} \;\; x>1 \\
\frac{I_0\left(\alpha\sqrt{1-(2 x-1)^2}\right)}
{I_0(\alpha)}, & \mbox{else}
\end{cases}
\f]
*
* \param x Argument \f$x\f$.
* \param alpha Parameter \f$\alpha\f$.
*
* \return Result \f$y\f$ when successful evaluated, else
* GSL_POSINF or GSL_NEGINF. Use the functions gsl_isinf()
* or gsl_finite() for result checking.
******************************************************************************/
double mathFuncKaiser (double x, double alpha);
#ifdef __cplusplus
}
#endif
#endif /* MATHFUNCS_H */
/******************************************************************************/
/* END OF FILE */
/******************************************************************************/
|