Mercurial > nand-ecoscentric
comparison packages/language/c/libm/current/include/math.h @ 0:3111d98ba7b3 ecos-v1_1-release
Initial commit of eCos version 1.1
| author | jlarmour |
|---|---|
| date | Tue, 11 May 1999 11:16:07 +0000 |
| parents | |
| children | 443894e2e912 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:3111d98ba7b3 |
|---|---|
| 1 #ifndef CYGONCE_LIBM_MATH_H | |
| 2 #define CYGONCE_LIBM_MATH_H | |
| 3 //=========================================================================== | |
| 4 // | |
| 5 // math.h | |
| 6 // | |
| 7 // Standard mathematical functions conforming to ANSI and other standards | |
| 8 // | |
| 9 //=========================================================================== | |
| 10 //####COPYRIGHTBEGIN#### | |
| 11 // | |
| 12 // ------------------------------------------- | |
| 13 // The contents of this file are subject to the Cygnus eCos Public License | |
| 14 // Version 1.0 (the "License"); you may not use this file except in | |
| 15 // compliance with the License. You may obtain a copy of the License at | |
| 16 // http://sourceware.cygnus.com/ecos | |
| 17 // | |
| 18 // Software distributed under the License is distributed on an "AS IS" | |
| 19 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | |
| 20 // License for the specific language governing rights and limitations under | |
| 21 // the License. | |
| 22 // | |
| 23 // The Original Code is eCos - Embedded Cygnus Operating System, released | |
| 24 // September 30, 1998. | |
| 25 // | |
| 26 // The Initial Developer of the Original Code is Cygnus. Portions created | |
| 27 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. | |
| 28 // ------------------------------------------- | |
| 29 // | |
| 30 //####COPYRIGHTEND#### | |
| 31 //=========================================================================== | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 34 // Author(s): jlarmour@cygnus.co.uk | |
| 35 // Contributors: jlarmour@cygnus.co.uk | |
| 36 // Date: 1998-02-13 | |
| 37 // Purpose: | |
| 38 // Description: Standard mathematical functions. These can be | |
| 39 // configured to conform to ANSI section 7.5. There are also | |
| 40 // a number of extensions conforming to IEEE-754 and behaviours | |
| 41 // compatible with other standards | |
| 42 // Usage: #include <math.h> | |
| 43 // | |
| 44 //####DESCRIPTIONEND#### | |
| 45 // | |
| 46 //=========================================================================== | |
| 47 | |
| 48 // CONFIGURATION | |
| 49 | |
| 50 #include <pkgconf/libm.h> // Configuration header | |
| 51 | |
| 52 // Include the Math library? | |
| 53 #ifdef CYGPKG_LIBM | |
| 54 | |
| 55 // INCLUDES | |
| 56 | |
| 57 #include <cyg/infra/cyg_type.h> // Common type definitions and support | |
| 58 #include <float.h> // Properties of FP representation on this | |
| 59 // platform | |
| 60 #include <sys/ieeefp.h> // Cyg_libm_ieee_double_shape_type | |
| 61 | |
| 62 // CONSTANT DEFINITIONS | |
| 63 | |
| 64 | |
| 65 // HUGE_VAL is a positive double (not necessarily representable as a float) | |
| 66 // representing infinity as specified in ANSI 7.5. cyg_libm_infinity is | |
| 67 // defined further down | |
| 68 #define HUGE_VAL (cyg_libm_infinity.value) | |
| 69 | |
| 70 | |
| 71 #ifndef CYGSYM_LIBM_NO_XOPEN_SVID_NAMESPACE_POLLUTION | |
| 72 // HUGE is defined in System V Interface Definition 3 (SVID3) as the largest | |
| 73 // finite single precision number | |
| 74 #define HUGE FLT_MAX // from float.h | |
| 75 | |
| 76 | |
| 77 // Values used in the type field of struct exception below | |
| 78 | |
| 79 #define DOMAIN 1 | |
| 80 #define SING 2 | |
| 81 #define OVERFLOW 3 | |
| 82 #define UNDERFLOW 4 | |
| 83 #define TLOSS 5 | |
| 84 #define PLOSS 6 | |
| 85 | |
| 86 | |
| 87 // TYPE DEFINITIONS | |
| 88 | |
| 89 // Things required to support matherr() ( see comments in <pkgconf/libm.h>) | |
| 90 | |
| 91 struct exception { | |
| 92 int type; // One of DOMAIN, SING, OVERFLOW, UNDERFLOW, TLOSS, PLOSS | |
| 93 char *name; // Name of the function generating the exception | |
| 94 double arg1; // First argument to the function | |
| 95 double arg2; // Second argument to the function | |
| 96 double retval; // Value to be returned - can be altered by matherr() | |
| 97 }; | |
| 98 | |
| 99 #endif // ifndef CYGSYM_LIBM_NO_XOPEN_SVID_NAMESPACE_POLLUTION | |
| 100 | |
| 101 | |
| 102 // GLOBALS | |
| 103 | |
| 104 externC const Cyg_libm_ieee_double_shape_type cyg_libm_infinity; | |
| 105 | |
| 106 //=========================================================================== | |
| 107 // FUNCTION PROTOTYPES | |
| 108 | |
| 109 // Functions not part of a standard | |
| 110 | |
| 111 // This retrieves a pointer to the current compatibility mode of the Math | |
| 112 // library. See <pkgconf/libm.h> for the definition of Cyg_libm_compat_t | |
| 113 | |
| 114 #ifdef CYGSEM_LIBM_THREAD_SAFE_COMPAT_MODE | |
| 115 | |
| 116 externC Cyg_libm_compat_t | |
| 117 cyg_libm_get_compat_mode( void ); | |
| 118 | |
| 119 externC Cyg_libm_compat_t | |
| 120 cyg_libm_set_compat_mode( Cyg_libm_compat_t ); | |
| 121 | |
| 122 #else | |
| 123 | |
| 124 externC Cyg_libm_compat_t cygvar_libm_compat_mode; | |
| 125 | |
| 126 // Defined as static inline as it is unlikely that anyone wants to take the | |
| 127 // address of these functions. | |
| 128 // | |
| 129 // This returns the current compatibility mode | |
| 130 | |
| 131 static inline Cyg_libm_compat_t | |
| 132 cyg_libm_get_compat_mode( void ) | |
| 133 { | |
| 134 return cygvar_libm_compat_mode; | |
| 135 } | |
| 136 | |
| 137 // This sets the compatibility mode, and returns the previous mode | |
| 138 static inline Cyg_libm_compat_t | |
| 139 cyg_libm_set_compat_mode( Cyg_libm_compat_t math_compat_mode) | |
| 140 { | |
| 141 Cyg_libm_compat_t oldmode; | |
| 142 | |
| 143 oldmode = cygvar_libm_compat_mode; | |
| 144 cygvar_libm_compat_mode = math_compat_mode; | |
| 145 return oldmode; | |
| 146 } | |
| 147 | |
| 148 #endif // ifdef CYGSEM_LIBM_THREAD_SAFE_COMPAT_MODE | |
| 149 | |
| 150 | |
| 151 //=========================================================================== | |
| 152 // Standard ANSI functions. Angles are always in radians | |
| 153 | |
| 154 // Trigonometric functions - ANSI 7.5.2 | |
| 155 | |
| 156 externC double | |
| 157 acos( double ); // arc cosine i.e. inverse cos | |
| 158 | |
| 159 externC double | |
| 160 asin( double ); // arc sine i.e. inverse sin | |
| 161 | |
| 162 externC double | |
| 163 atan( double ); // arc tan i.e. inverse tan | |
| 164 | |
| 165 externC double | |
| 166 atan2( double, double ); // arc tan of (first arg/second arg) using signs | |
| 167 // of args to determine quadrant | |
| 168 | |
| 169 externC double | |
| 170 cos( double ); // cosine | |
| 171 | |
| 172 externC double | |
| 173 sin( double ); // sine | |
| 174 | |
| 175 externC double | |
| 176 tan( double ); // tangent | |
| 177 | |
| 178 // Hyperbolic functions - ANSI 7.5.3 | |
| 179 | |
| 180 externC double | |
| 181 cosh( double ); // hyperbolic cosine | |
| 182 | |
| 183 externC double | |
| 184 sinh( double ); // hyperbolic sine | |
| 185 | |
| 186 externC double | |
| 187 tanh( double ); // hyperbolic tangent | |
| 188 | |
| 189 // Exponential and Logarithmic Functions - ANSI 7.5.4 | |
| 190 | |
| 191 externC double | |
| 192 exp( double ); // exponent | |
| 193 | |
| 194 externC double | |
| 195 frexp( double, int * ); // break number into normalized fraction (returned) | |
| 196 // and integral power of 2 (second arg) | |
| 197 | |
| 198 externC double | |
| 199 ldexp( double, int ); // multiples number by integral power of 2 | |
| 200 | |
| 201 externC double | |
| 202 log( double ); // natural logarithm | |
| 203 | |
| 204 externC double | |
| 205 log10( double ); // base ten logarithm | |
| 206 | |
| 207 externC double | |
| 208 modf( double, double * ); // break number into integral and fractional | |
| 209 // parts, each of which has same sign as arg. | |
| 210 // It returns signed fractional part, and | |
| 211 // puts integral part in second arg | |
| 212 | |
| 213 // Power Functions - ANSI 7.5.5 | |
| 214 | |
| 215 externC double | |
| 216 pow( double, double ); // (1st arg) to the power of (2nd arg) | |
| 217 | |
| 218 externC double | |
| 219 sqrt( double ); // square root | |
| 220 | |
| 221 // Nearest integer, absolute value and remainder functions - ANSI 7.5.6 | |
| 222 | |
| 223 externC double | |
| 224 ceil( double ); // smallest integer >= arg | |
| 225 | |
| 226 externC double | |
| 227 fabs( double ); // absolute value | |
| 228 | |
| 229 externC double | |
| 230 floor( double ); // largest integer <= arg | |
| 231 | |
| 232 externC double | |
| 233 fmod( double, double ); // remainder of (1st arg)/(2nd arg) | |
| 234 | |
| 235 //=========================================================================== | |
| 236 // Other standard functions | |
| 237 | |
| 238 #ifndef CYGSYM_LIBM_NO_XOPEN_SVID_NAMESPACE_POLLUTION | |
| 239 externC int | |
| 240 matherr( struct exception * ); // User-overridable error handling - see | |
| 241 #endif // <pkgconf/libm.h> for a discussion | |
| 242 | |
| 243 // scalb*() | |
| 244 | |
| 245 externC double // scalbn(x,n) returns x*(2**n) | |
| 246 scalbn( double, int ); | |
| 247 | |
| 248 #ifdef CYGFUN_LIBM_SVID3_scalb | |
| 249 | |
| 250 externC double | |
| 251 scalb( double, double ); // as above except n is a floating point arg | |
| 252 | |
| 253 #else | |
| 254 externC double | |
| 255 scalb( double, int ); // as scalbn() | |
| 256 | |
| 257 #endif // ifdef CYGFUN_LIBM_SVID3_scalb | |
| 258 | |
| 259 // And the rest | |
| 260 | |
| 261 | |
| 262 externC int // whether the argument is NaN | |
| 263 isnan( double ); | |
| 264 | |
| 265 externC int | |
| 266 finite( double ); // whether the argument is finite | |
| 267 | |
| 268 | |
| 269 //=========================================================================== | |
| 270 // Non-standard functions | |
| 271 | |
| 272 externC double // copysign(x,y) returns a number with | |
| 273 copysign ( double, double ); // the absolute value of x and the sign of y | |
| 274 | |
| 275 externC double // rounds to an integer according to the | |
| 276 rint( double ); // current rounding mode | |
| 277 | |
| 278 | |
| 279 // BSD functions | |
| 280 | |
| 281 externC double // expm1(x) returns the equivalent of | |
| 282 expm1( double ); // (exp(x) - 1) but more accurately when | |
| 283 // x tends to zero | |
| 284 | |
| 285 | |
| 286 #endif // ifdef CYGPKG_LIBM | |
| 287 | |
| 288 #endif // CYGONCE_LIBM_MATH_H multiple inclusion protection | |
| 289 | |
| 290 // EOF math.h |
