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