aboutsummaryrefslogtreecommitdiff
path: root/arch/all/math/include/math.h
blob: 4752354f5696a581037e3f2adbd9f61416feac77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* ****************************************************************************
 * math.h -- Math functions.
 *
 * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
 *
 * This file is part of the 'all/math' module in libcarrot, an experimental
 * modular libc project.
 *
 * This file is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * This file is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Lesser Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this file. If not, see <http://www.gnu.org/licenses/>.
 * ************************************************************************* */
#include <cdefs.h>
#include <errno.h>
__BEGIN_NAMESPACE_STD

/* the type */
typedef double double_t;

/* useful constants */
#define M_El         2.718281828459045235360287471352662498L /* e */
#define M_LOG2El     1.442695040888963407359924681001892137L /* log_2 e */
#define M_LOG10El    0.434294481903251827651128918916605082L /* log_10 e */
#define M_LN2l       0.693147180559945309417232121458176568L /* log_e 2 */
#define M_LN10l      2.302585092994045684017991454684364208L /* log_e 10 */
#define M_PIl        3.141592653589793238462643383279502884L /* pi */
#define M_PI_2l      1.570796326794896619231321691639751442L /* pi/2 */
#define M_PI_4l      0.785398163397448309615660845819875721L /* pi/4 */
#define M_1_PIl      0.318309886183790671537767526745028724L /* 1/pi */
#define M_2_PIl      0.636619772367581343075535053490057448L /* 2/pi */
#define M_2_SQRTPIl  1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
#define M_SQRT2l     1.414213562373095048801688724209698079L /* sqrt(2) */
#define M_SQRT1_2l   0.707106781186547524400844362104849039L /* 1/sqrt(2) */

/* check if something is NaN */
#define __isnan(_X) ((_X) != (_X))
/* ************************************************************************* */
/*  Comparison macros                                                        */
/* ************************************************************************* */
/* These macros, except `isunordered`, unlike their "simple" equivalent
 * (such as `x > y` for `isgreater`), do not raise the "invalid" floating-point
 * exception when x and y are unordered.
 *
 * Determines whether a floating-point number is greater than an other. */
#define isgreater(_X, _Y) \
	(!isunordered(_X, _Y) && (_X) >  (_Y))

/* Determines whether a floating-point number is greater or equal to
 * an other. */
#define isgreaterequal(_X, _Y) \
	(!isunordered(_X, _Y) && (_X) >= (_Y))

/* Determines whether a floating-point number is less than an other. */
#define isless(_X, _Y) \
	(!isunordered(_X, _Y) && (_X) <  (_Y))

/* Determines whether a floating-point number is less or equal to an other. */
#define islessequal(_X, _Y) \
	(!isunordered(_X, _Y) && (_X) <= (_Y))

/* Determines whether a floating-point number is less or greater than
 * an other. */
#define islessgreater(_X, _Y) \
	(!isunordered(_X, _Y) && ((_X) < (_Y) || (_X) > (_Y)))

/* Determines whether two floating-point numbers are unordered. */
#define isunordered(_X, _Y)     (__isnan(_X) || __isnan(_Y))
/* ************************************************************************* */
/*  Utilities                                                                */
/* ************************************************************************* */
__BEGIN_DECLS

/* Convert floating-point number to fractional and integral components */
extern __pure double_t frexp _OF((double_t __x, int *__exp)) __THROW;

/* Multiply floating-point number by integral power of 2 */
extern __pure double_t ldexp _OF((double_t __x, int __exp)) __THROW;

/* Extract signed integral and fractional values from floating-point number */
extern __pure double_t modf  _OF((double_t __x, double_t *__iptr)) __THROW;

/* Find smallest integral value not less than argument */
extern __pure double_t ceil  _OF((double_t __x)) __THROW;

/* Absolute value of floating-point number */
extern __pure double_t fabs  _OF((double_t __x)) __THROW;

/* Largest integral value not greater than argument */
extern __pure double_t floor _OF((double_t __x)) __THROW;

/* Floating-point remainder function */
extern __pure double_t fmod  _OF((double_t __x, double_t __y)) __THROW;

/* Arc cosine function */
extern __pure double_t acos  _OF((double_t __x)) __THROW;

/* Arc sine function */
extern __pure double_t asin  _OF((double_t __x)) __THROW;

/* Arc tangent function */
extern __pure double_t atan  _OF((double_t __x)) __THROW;

/* Arc tangent function of two variables */
extern __pure double_t atan2 _OF((double_t __y, double_t __x)) __THROW;

#if __USE_C99
__END_DECLS
__END_NAMESPACE_STD
__BEGIN_NAMESPACE_C99
__BEGIN_DECLS
/* Inverse hyperbolic cosine function */
extern __pure double_t acosh _OF((double_t __x)) __THROW;

/* Inverse hyperbolic sine function */
extern __pure double_t asinh _OF((double_t __x)) __THROW;

/* Inverse hyperbolic tangeant function */
extern __pure double_t atanh _OF((double_t __x)) __THROW;

__END_DECLS
__END_NAMESPACE_C99
__BEGIN_NAMESPACE_STD
__BEGIN_DECLS
#endif

/* Cosine function */
extern __pure double_t cos   _OF((double_t __x)) __THROW;

/* Sine function */
extern __pure double_t sin   _OF((double_t __x)) __THROW;

/* Tangent function */
extern __pure double_t tan   _OF((double_t __x)) __THROW;

/* Hyperbolic cosine function */
extern __pure double_t cosh  _OF((double_t __x)) __THROW;

/* Hyperbolic tangent function */
extern __pure double_t tanh  _OF((double_t __x)) __THROW;

/* Hyperbolic sine function */
extern __pure double_t sinh  _OF((double_t __x)) __THROW;

/* Base-e exponential function */
extern __pure double_t exp   _OF((double_t __x)) __THROW;

/* Natural logarithmic function */
extern __pure double_t log   _OF((double_t __x)) __THROW;

/* Base-10 logarithmic function */
extern __pure double_t log10 _OF((double_t __x)) __THROW;

/* Power function */
extern __pure double_t pow   _OF((double_t __x, double_t __y)) __THROW;

/* Square root function */
extern __pure double_t sqrt  _OF((double_t __x)) __THROW;

__END_DECLS
__END_NAMESPACE_STD
#if __USE_C99
__BEGIN_NAMESPACE_C99
__BEGIN_DECLS

/* Euclidean distance function */
extern __pure double_t hypot _OF((double_t __x, double_t __y)) __THROW;

/* Cube root function */
extern __pure double_t cbrt  _OF((double_t __x)) __THROW;

__END_DECLS
__END_NAMESPACE_C99
#endif
#include <mathf.h>