OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [language/] [c/] [libm/] [v2_0/] [include/] [math.h] - Blame information for rev 228

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
#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
//####ECOSGPLCOPYRIGHTBEGIN####
11
// -------------------------------------------
12
// This file is part of eCos, the Embedded Configurable Operating System.
13
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
14
//
15
// eCos is free software; you can redistribute it and/or modify it under
16
// the terms of the GNU General Public License as published by the Free
17
// Software Foundation; either version 2 or (at your option) any later version.
18
//
19
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
21
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22
// for more details.
23
//
24
// You should have received a copy of the GNU General Public License along
25
// with eCos; if not, write to the Free Software Foundation, Inc.,
26
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27
//
28
// As a special exception, if other files instantiate templates or use macros
29
// or inline functions from this file, or you compile this file and link it
30
// with other works to produce a work based on this file, this file does not
31
// by itself cause the resulting work to be covered by the GNU General Public
32
// License. However the source code for this file must still be made available
33
// in accordance with section (3) of the GNU General Public License.
34
//
35
// This exception does not invalidate any other reasons why a work based on
36
// this file might be covered by the GNU General Public License.
37
//
38
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39
// at http://sources.redhat.com/ecos/ecos-license/
40
// -------------------------------------------
41
//####ECOSGPLCOPYRIGHTEND####
42
//===========================================================================
43
//#####DESCRIPTIONBEGIN####
44
//
45
// Author(s):   jlarmour
46
// Contributors:  jlarmour
47
// Date:        1998-02-13
48
// Purpose:     
49
// Description: Standard mathematical functions. These can be
50
//              configured to conform to ANSI section 7.5. There are also
51
//              a number of extensions conforming to IEEE-754 and behaviours
52
//              compatible with other standards
53
// Usage:       #include <math.h>
54
//
55
//####DESCRIPTIONEND####
56
//
57
//===========================================================================
58
 
59
// CONFIGURATION
60
 
61
#include <pkgconf/libm.h>   // Configuration header
62
 
63
// Include the Math library?
64
#ifdef CYGPKG_LIBM     
65
 
66
// INCLUDES
67
 
68
#include <cyg/infra/cyg_type.h>    // Common type definitions and support
69
#include <float.h>                 // Properties of FP representation on this
70
                                   // platform
71
#include <sys/ieeefp.h>            // Cyg_libm_ieee_double_shape_type
72
 
73
// CONSTANT DEFINITIONS
74
 
75
 
76
// HUGE_VAL is a positive double (not necessarily representable as a float)
77
// representing infinity as specified in ANSI 7.5. cyg_libm_infinity is
78
// defined further down
79
#define HUGE_VAL        (cyg_libm_infinity.value)
80
 
81
 
82
#ifndef CYGSYM_LIBM_NO_XOPEN_SVID_NAMESPACE_POLLUTION
83
// HUGE is defined in System V Interface Definition 3 (SVID3) as the largest
84
// finite single precision number
85
#define HUGE            FLT_MAX    // from float.h
86
 
87
 
88
// Values used in the type field of struct exception below
89
 
90
#define DOMAIN          1
91
#define SING            2
92
#define OVERFLOW        3
93
#define UNDERFLOW       4
94
#define TLOSS           5
95
#define PLOSS           6
96
 
97
 
98
// TYPE DEFINITIONS
99
 
100
// Things required to support matherr() ( see comments in <pkgconf/libm.h>)
101
 
102
struct exception {
103
    int type;       // One of DOMAIN, SING, OVERFLOW, UNDERFLOW, TLOSS, PLOSS
104
    char *name;     // Name of the function generating the exception
105
    double arg1;    // First argument to the function
106
    double arg2;    // Second argument to the function
107
    double retval;  // Value to be returned - can be altered by matherr()
108
};
109
 
110
#endif // ifndef CYGSYM_LIBM_NO_XOPEN_SVID_NAMESPACE_POLLUTION
111
 
112
 
113
// GLOBALS
114
 
115
externC const Cyg_libm_ieee_double_shape_type cyg_libm_infinity;
116
 
117
//===========================================================================
118
// FUNCTION PROTOTYPES
119
 
120
// Functions not part of a standard
121
 
122
// This retrieves a pointer to the current compatibility mode of the Math
123
// library. See <pkgconf/libm.h> for the definition of Cyg_libm_compat_t
124
 
125
#ifdef CYGSEM_LIBM_THREAD_SAFE_COMPAT_MODE
126
 
127
externC Cyg_libm_compat_t
128
cyg_libm_get_compat_mode( void );
129
 
130
externC Cyg_libm_compat_t
131
cyg_libm_set_compat_mode( Cyg_libm_compat_t );
132
 
133
#else
134
 
135
externC Cyg_libm_compat_t cygvar_libm_compat_mode;
136
 
137
// Defined as static inline as it is unlikely that anyone wants to take the
138
// address of these functions.
139
//
140
// This returns the current compatibility mode
141
 
142
static inline Cyg_libm_compat_t
143
cyg_libm_get_compat_mode( void )
144
{
145
    return cygvar_libm_compat_mode;
146
}
147
 
148
// This sets the compatibility mode, and returns the previous mode
149
static inline Cyg_libm_compat_t
150
cyg_libm_set_compat_mode( Cyg_libm_compat_t math_compat_mode)
151
{
152
    Cyg_libm_compat_t oldmode;
153
 
154
    oldmode = cygvar_libm_compat_mode;
155
    cygvar_libm_compat_mode = math_compat_mode;
156
    return oldmode;
157
}
158
 
159
#endif // ifdef CYGSEM_LIBM_THREAD_SAFE_COMPAT_MODE
160
 
161
#ifdef CYGSEM_LIBM_THREAD_SAFE_GAMMA_FUNCTIONS
162
 
163
// FIXME: these need to be documented and signgam mentioned as non-ISO
164
// This returns the address of the signgam variable used by the gamma*() and
165
// lgamma*() functions
166
externC int *
167
cyg_libm_get_signgam_p( void );
168
 
169
#define signgam (*cyg_libm_get_signgam_p())
170
 
171
#else
172
 
173
externC int signgam;
174
 
175
#endif // ifdef CYGSEM_LIBM_THREAD_SAFE_GAMMA_FUNCTIONS
176
 
177
//===========================================================================
178
// Standard ANSI functions. Angles are always in radians
179
 
180
// Trigonometric functions - ANSI 7.5.2
181
 
182
externC double
183
acos( double );            // arc cosine i.e. inverse cos
184
 
185
externC double
186
asin( double );            // arc sine i.e. inverse sin
187
 
188
externC double
189
atan( double );            // arc tan i.e. inverse tan
190
 
191
externC double
192
atan2( double, double );   // arc tan of (first arg/second arg) using signs
193
                           // of args to determine quadrant
194
 
195
externC double
196
cos( double );             // cosine
197
 
198
externC double
199
sin( double );             // sine
200
 
201
externC double
202
tan( double );             // tangent
203
 
204
// Hyperbolic functions - ANSI 7.5.3
205
 
206
externC double
207
cosh( double );            // hyperbolic cosine
208
 
209
externC double
210
sinh( double );            // hyperbolic sine
211
 
212
externC double
213
tanh( double );            // hyperbolic tangent
214
 
215
// Exponential and Logarithmic Functions - ANSI 7.5.4
216
 
217
externC double
218
exp( double );             // exponent
219
 
220
externC double
221
frexp( double, int * );    // break number into normalized fraction (returned)
222
                           // and integral power of 2 (second arg)
223
 
224
externC double
225
ldexp( double, int );      // multiples number by integral power of 2 
226
 
227
externC double
228
log( double );             // natural logarithm
229
 
230
externC double
231
log10( double );           // base ten logarithm
232
 
233
externC double
234
modf( double, double * );  // break number into integral and fractional
235
                           // parts, each of which has same sign as arg.
236
                           // It returns signed fractional part, and
237
                           // puts integral part in second arg
238
 
239
// Power Functions - ANSI 7.5.5
240
 
241
externC double
242
pow( double, double );     // (1st arg) to the power of (2nd arg)
243
 
244
externC double
245
sqrt( double );            // square root
246
 
247
// Nearest integer, absolute value and remainder functions - ANSI 7.5.6
248
 
249
externC double
250
ceil( double );            // smallest integer >= arg
251
 
252
externC double
253
fabs( double );            // absolute value
254
 
255
externC double
256
floor( double );           // largest integer <= arg
257
 
258
externC double
259
fmod( double, double );    // remainder of (1st arg)/(2nd arg)
260
 
261
//===========================================================================
262
// Other standard functions
263
 
264
#ifndef CYGSYM_LIBM_NO_XOPEN_SVID_NAMESPACE_POLLUTION
265
externC int
266
matherr( struct exception * );    // User-overridable error handling - see
267
#endif                            // <pkgconf/libm.h> for a discussion
268
 
269
// FIXME: from here needs to be documented and mentioned as non-ISO
270
// Arc Hyperbolic trigonometric functions
271
 
272
externC double
273
acosh( double );                  // Arc hyperbolic cos i.e. inverse cosh
274
 
275
externC double
276
asinh( double );                  // Arc hyperbolic sin i.e. inverse sinh
277
 
278
externC double
279
atanh( double );                  // Arc hyperbolic tan i.e. inverse tanh
280
 
281
// Error functions
282
 
283
externC double                    // Error function, such that
284
erf( double );                    // erf(x) = 2/sqrt(pi) * integral from
285
                                  // 0 to x of e**(-t**2) dt
286
 
287
externC double                    // Complementary error function - simply
288
erfc( double );                   // 1.0 - erf(x)
289
 
290
// Gamma functions
291
 
292
externC double                    // Logarithm of the absolute value of the
293
lgamma( double );                 // gamma function of the argument. The
294
                                  // integer signgam is used to store the
295
                                  // sign of the gamma function of the arg
296
 
297
externC double
298
lgamma_r( double, int * );        // Re-entrant version of the above, where
299
                                  // the user passes the location of signgam
300
                                  // as the second argument
301
 
302
externC double                    // Identical to lgamma()!
303
gamma( double );                  // The reasons for this are historical,
304
                                  // and may be changed in future standards
305
                                  //
306
                                  // To get the real gamma function, you should
307
                                  // use: l=lgamma(x); g=signgam*exp(l);
308
                                  //
309
                                  // Do not just do signgam*exp(lgamma(x))
310
                                  // as lgamma() modifies signgam
311
 
312
externC double
313
gamma_r( double, int * );         // Identical to lgamma_r(). See above.
314
 
315
 
316
// Bessel functions
317
 
318
externC double                    // Zero-th order Bessel function of the
319
j0( double );                     // first kind at the ordinate of the argument
320
 
321
externC double                    // First-order Bessel function of the
322
j1( double );                     // first kind at the ordinate of the argument
323
 
324
externC double                    // Bessel function of the first kind of the
325
jn( int, double );                // order of the first argument at the
326
                                  // ordinate of the second argument
327
 
328
externC double                    // Zero-th order Bessel function of the
329
y0( double );                     // second kind at the ordinate of the
330
                                  // argument
331
 
332
externC double                    // First-order Bessel function of the
333
y1( double );                     // second kind at the ordinate of the
334
                                  // argument
335
 
336
externC double                    // Bessel function of the second kind of the
337
yn( int, double );                // order of the first argument at the
338
                                  // ordinate of the second argument
339
 
340
// scalb*()
341
 
342
externC double                    // scalbn(x,n) returns x*(2**n)
343
scalbn( double, int );
344
 
345
#ifdef CYGFUN_LIBM_SVID3_scalb
346
 
347
externC double
348
scalb( double, double );          // as above except n is a floating point arg
349
 
350
#else
351
externC double
352
scalb( double, int );             // as scalbn()
353
 
354
#endif // ifdef CYGFUN_LIBM_SVID3_scalb
355
 
356
// And the rest
357
 
358
externC double
359
cbrt( double );                   // Cube Root
360
 
361
externC double                    // hypotenuse function, defined such that:
362
hypot( double, double );          // hypot(x,y)==sqrt(x**2 + y**2)
363
 
364
externC int                       // whether the argument is NaN
365
isnan( double );
366
 
367
externC int
368
finite( double );                 // whether the argument is finite
369
 
370
externC double                    // logb returns the binary exponent of its
371
logb( double );                   // argument as an integral value
372
                                  // This is not recommended - use ilogb
373
                                  // instead
374
 
375
externC int                       // As for logb, but has the more correct
376
ilogb( double );                  // return value type of int
377
 
378
 
379
externC double                    // nextafter(x,y) returns the next
380
nextafter( double, double );      // representable floating point number
381
                                  // adjacent to x in the direction of y
382
                                  // i.e. the next greater FP if y>x, the next
383
                                  // less FP if y<x, or just x if y==x
384
 
385
externC double                    // remainder(x,y) returns the remainder
386
remainder( double, double );      // when x is divided by y
387
 
388
externC double                    // IEEE Test Vector
389
significand( double );            // significand(x) computes:
390
                                  //   scalb(x, (double) -ilogb(x))
391
 
392
//===========================================================================
393
// Non-standard functions
394
 
395
externC double                    // copysign(x,y) returns a number with
396
copysign ( double, double );      // the absolute value of x and the sign of y
397
 
398
externC double                    // rounds to an integer according to the
399
rint( double );                   // current rounding mode
400
 
401
 
402
// BSD functions
403
 
404
externC double                    // expm1(x) returns the equivalent of
405
expm1( double );                  // (exp(x) - 1) but more accurately when
406
                                  // x tends to zero
407
 
408
externC double                    // log1p(x) returns the equivalent of
409
log1p( double );                  // log(1+x) but more accurately when
410
                                  // x tends to zero
411
 
412
#endif // ifdef CYGPKG_LIBM     
413
 
414
#endif // CYGONCE_LIBM_MATH_H multiple inclusion protection
415
 
416
// EOF math.h

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.