f5f0b7099e4ada97d963abfe062e897a5ac43dcf
[fw/sdcc] / device / include / math.h
1 /*  math.h: Floating point math function declarations
2
3     Copyright (C) 2001  Jesus Calvino-Fraga, jesusc@ieee.org 
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Lesser General Public
7     License as published by the Free Software Foundation; either
8     version 2.1 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13     Lesser General Public License for more details.
14
15     You should have received a copy of the GNU Lesser General Public
16     License along with this library; if not, write to the Free Software
17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA */
18
19 /* Version 1.0 - Initial release */
20
21 #ifndef _INC_MATH
22 #define _INC_MATH
23
24 #define PI          3.1415926536
25 #define TWO_PI      6.2831853071
26 #define HALF_PI     1.5707963268
27 #define QUART_PI    0.7853981634
28 #define iPI         0.3183098862
29 #define iTWO_PI     0.1591549431
30 #define TWO_O_PI    0.6366197724
31
32 // EPS=B**(-t/2), where B is the radix of the floating-point representation
33 // and there are t base-B digits in the significand.  Therefore, for floats
34 // EPS=2**(-12).  Also define EPS2=EPS*EPS.
35 #define EPS 244.14062E-6
36 #define EPS2 59.6046E-9
37 #define XMAX 3.402823466E+38
38
39 union float_long
40 {
41     float f;
42     long l;
43 };
44
45 #if defined(SDCC_MATH_LIB) && defined(SDCC_mcs51) && !defined(SDCC_USE_XSTACK) && !defined(SDCC_STACK_AUTO) && !defined(_SDCC_NO_ASM_LIB_FUNCS)
46 // Compile the mcs51 assembly version only when all these
47 // conditions are met.  Since not all the functions are
48 // reentrant, do not compile with --stack-auto is used.
49 #define MATH_ASM_MCS51
50 #endif
51
52
53 /* Functions on the z80 & gbz80 are always reentrant and so the "reentrant" */
54 /* keyword is not defined. */
55 #if defined(SDCC_z80) || defined(SDCC_gbz80)
56 #define _FLOAT_FUNC_REENTRANT
57 #else
58 #define _FLOAT_FUNC_REENTRANT reentrant
59 #endif
60
61 /**********************************************
62  * Prototypes for float ANSI C math functions *
63  **********************************************/
64
65 /* Trigonometric functions */
66 float sinf(const float x) _FLOAT_FUNC_REENTRANT;
67 float cosf(const float x) _FLOAT_FUNC_REENTRANT;
68 float tanf(const float x) _FLOAT_FUNC_REENTRANT;
69 float cotf(const float x) _FLOAT_FUNC_REENTRANT;
70 float asinf(const float x) _FLOAT_FUNC_REENTRANT;
71 float acosf(const float x) _FLOAT_FUNC_REENTRANT;
72 float atanf(const float x) _FLOAT_FUNC_REENTRANT;
73 float atan2f(const float x, const float y);
74
75 /* Hyperbolic functions */
76 float sinhf(const float x) _FLOAT_FUNC_REENTRANT;
77 float coshf(const float x) _FLOAT_FUNC_REENTRANT;
78 float tanhf(const float x) _FLOAT_FUNC_REENTRANT;
79
80 /* Exponential, logarithmic and power functions */
81 float expf(const float x);
82 float logf(const float x) _FLOAT_FUNC_REENTRANT;
83 float log10f(const float x) _FLOAT_FUNC_REENTRANT;
84 float powf(const float x, const float y);
85 float sqrtf(const float a) _FLOAT_FUNC_REENTRANT;
86
87 /* Nearest integer, absolute value, and remainder functions */
88 float fabsf(const float x) _FLOAT_FUNC_REENTRANT;
89 float frexpf(const float x, int *pw2);
90 float ldexpf(const float x, const int pw2);
91 float ceilf(float x) _FLOAT_FUNC_REENTRANT;
92 float floorf(float x) _FLOAT_FUNC_REENTRANT;
93 float modff(float x, float * y);
94
95 #endif  /* _INC_MATH */