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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [language/] [c/] [libm/] [current/] [include/] [math.h] - Blame information for rev 825

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

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

powered by: WebSVN 2.1.0

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