1 /* gsl_math.h 2 * 3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2004, 2007 Gerard Jungman, Brian Gough 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 3 of the License, or (at 8 * your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 */ 19 20 #ifndef __GSL_MATH_H__ 21 #define __GSL_MATH_H__ 22 #include <math.h> 23 #include <gsl/gsl_sys.h> 24 #include <gsl/gsl_inline.h> 25 #include <gsl/gsl_machine.h> 26 #include <gsl/gsl_precision.h> 27 #include <gsl/gsl_nan.h> 28 #include <gsl/gsl_pow_int.h> 29 #include <gsl/gsl_minmax.h> 30 31 #ifndef M_E 32 #define M_E 2.71828182845904523536028747135 /* e */ 33 #endif 34 35 #ifndef M_LOG2E 36 #define M_LOG2E 1.44269504088896340735992468100 /* log_2 (e) */ 37 #endif 38 39 #ifndef M_LOG10E 40 #define M_LOG10E 0.43429448190325182765112891892 /* log_10 (e) */ 41 #endif 42 43 #ifndef M_SQRT2 44 #define M_SQRT2 1.41421356237309504880168872421 /* sqrt(2) */ 45 #endif 46 47 #ifndef M_SQRT1_2 48 #define M_SQRT1_2 0.70710678118654752440084436210 /* sqrt(1/2) */ 49 #endif 50 51 52 #ifndef M_SQRT3 53 #define M_SQRT3 1.73205080756887729352744634151 /* sqrt(3) */ 54 #endif 55 56 #ifndef M_PI 57 #define M_PI 3.14159265358979323846264338328 /* pi */ 58 #endif 59 60 #ifndef M_PI_2 61 #define M_PI_2 1.57079632679489661923132169164 /* pi/2 */ 62 #endif 63 64 #ifndef M_PI_4 65 #define M_PI_4 0.78539816339744830961566084582 /* pi/4 */ 66 #endif 67 68 #ifndef M_SQRTPI 69 #define M_SQRTPI 1.77245385090551602729816748334 /* sqrt(pi) */ 70 #endif 71 72 #ifndef M_2_SQRTPI 73 #define M_2_SQRTPI 1.12837916709551257389615890312 /* 2/sqrt(pi) */ 74 #endif 75 76 #ifndef M_1_PI 77 #define M_1_PI 0.31830988618379067153776752675 /* 1/pi */ 78 #endif 79 80 #ifndef M_2_PI 81 #define M_2_PI 0.63661977236758134307553505349 /* 2/pi */ 82 #endif 83 84 #ifndef M_LN10 85 #define M_LN10 2.30258509299404568401799145468 /* ln(10) */ 86 #endif 87 88 #ifndef M_LN2 89 #define M_LN2 0.69314718055994530941723212146 /* ln(2) */ 90 #endif 91 92 #ifndef M_LNPI 93 #define M_LNPI 1.14472988584940017414342735135 /* ln(pi) */ 94 #endif 95 96 #ifndef M_EULER 97 #define M_EULER 0.57721566490153286060651209008 /* Euler constant */ 98 #endif 99 100 #undef __BEGIN_DECLS 101 #undef __END_DECLS 102 #ifdef __cplusplus 103 # define __BEGIN_DECLS extern "C" { 104 # define __END_DECLS } 105 #else 106 # define __BEGIN_DECLS /* empty */ 107 # define __END_DECLS /* empty */ 108 #endif 109 110 __BEGIN_DECLS 111 112 /* other needlessly compulsive abstractions */ 113 114 #define GSL_IS_ODD(n) ((n) & 1) 115 #define GSL_IS_EVEN(n) (!(GSL_IS_ODD(n))) 116 #define GSL_SIGN(x) ((x) >= 0.0 ? 1 : -1) 117 118 /* Return nonzero if x is a real number, i.e. non NaN or infinite. */ 119 #define GSL_IS_REAL(x) (gsl_finite(x)) 120 121 /* Definition of an arbitrary function with parameters */ 122 123 struct gsl_function_struct 124 { 125 double (* function) (double x, void * params); 126 void * params; 127 }; 128 129 typedef struct gsl_function_struct gsl_function ; 130 131 #define GSL_FN_EVAL(F,x) (*((F)->function))(x,(F)->params) 132 133 /* Definition of an arbitrary function returning two values, r1, r2 */ 134 135 struct gsl_function_fdf_struct 136 { 137 double (* f) (double x, void * params); 138 double (* df) (double x, void * params); 139 void (* fdf) (double x, void * params, double * f, double * df); 140 void * params; 141 }; 142 143 typedef struct gsl_function_fdf_struct gsl_function_fdf ; 144 145 #define GSL_FN_FDF_EVAL_F(FDF,x) (*((FDF)->f))(x,(FDF)->params) 146 #define GSL_FN_FDF_EVAL_DF(FDF,x) (*((FDF)->df))(x,(FDF)->params) 147 #define GSL_FN_FDF_EVAL_F_DF(FDF,x,y,dy) (*((FDF)->fdf))(x,(FDF)->params,(y),(dy)) 148 149 150 /* Definition of an arbitrary vector-valued function with parameters */ 151 152 struct gsl_function_vec_struct 153 { 154 int (* function) (double x, double y[], void * params); 155 void * params; 156 }; 157 158 typedef struct gsl_function_vec_struct gsl_function_vec ; 159 160 #define GSL_FN_VEC_EVAL(F,x,y) (*((F)->function))(x,y,(F)->params) 161 162 __END_DECLS 163 164 #endif /* __GSL_MATH_H__ */ 165