AVR-LibC  2.3.0
Standard C library for AVR-GCC
 

AVR-LibC Manual

AVR-LibC Sources

Main Page

User Manual

Lib­rary Refe­rence

FAQ

Exam­ple Pro­jects

Index

Loading...
Searching...
No Matches
math.h
Go to the documentation of this file.
1/* Copyright (c) 2002,2007-2009 Michael Stumpf
2 Copyright (c) 2023-2025 Georg-Johann Lay
3
4 Portions of documentation Copyright (c) 1990 - 1994
5 The Regents of the University of California.
6
7 All rights reserved.
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
11
12 * Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14
15 * Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in
17 the documentation and/or other materials provided with the
18 distribution.
19
20 * Neither the name of the copyright holders nor the names of
21 contributors may be used to endorse or promote products derived
22 from this software without specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE. */
35
36/*
37 math.h - mathematical functions
38
39 Author : Michael Stumpf
40 Michael.Stumpf@t-online.de
41
42 __ATTR_CONST__ added by marekm@linux.org.pl for functions
43 that "do not examine any values except their arguments, and have
44 no effects except the return value", for better optimization by gcc.
45 */
46
47#ifndef __MATH_H
48#define __MATH_H
49
50#ifndef __DOXYGEN__
51/* In pursue of old GCC versions... */
52#ifndef __SIZEOF_FLOAT__
53#define __SIZEOF_FLOAT__ 4
54#endif
55#ifndef __SIZEOF_DOUBLE__
56#define __SIZEOF_DOUBLE__ 4
57#endif
58#ifndef __SIZEOF_LONG_DOUBLE__
59#define __SIZEOF_LONG_DOUBLE__ 4
60#endif
61#endif /* !Doxygen */
62
63#ifdef __cplusplus
64extern "C" {
65#endif
66
67/** \file */
68/** \defgroup avr_math <math.h>: Mathematics
69 \code #include <math.h> \endcode
70
71 This header file declares basic mathematics constants and
72 functions.
73
74 <b>Notes:</b>
75
76 - Math functions do not raise exceptions and do not change the
77 \c errno variable. Therefore the majority of them are declared
78 with \c const attribute, for better optimization by GCC.
79 - 64-bit floating-point arithmetic is only available in
80 <a href="https://gcc.gnu.org/gcc-10/changes.html#avr">GCC v10</a>
81 and up.
82 The size of the \c double and \c long \c double type can be selected
83 at compile-time with options like <tt>-mdouble=64</tt> and
84 <tt>-mlong-double=32</tt>. Whether such options are available,
85 and their default values, depend on how the compiler has been configured.
86 - The implementation of 64-bit floating-point arithmetic has some
87 shortcomings and limitations, see the
88 <a href="https://gcc.gnu.org/wiki/avr-gcc#Libf7">avr-gcc Wiki</a>
89 for details.
90
91 See also some benchmarks for \ref bench_libm "IEEE single"
92 and \ref bench_libf7 "IEEE double".
93*/
94
95
96/** \ingroup avr_math */
97/**@{*/
98
99/** The constant Euler's number \a e. */
100#define M_E 2.7182818284590452354
101
102/** The constant logarithm of Euler's number \a e to base 2. */
103#define M_LOG2E 1.4426950408889634074
104
105/** The constant logarithm of Euler's number \a e to base 10. */
106#define M_LOG10E 0.43429448190325182765
107
108/** The constant natural logarithm of 2. */
109#define M_LN2 0.69314718055994530942
110
111/** The constant natural logarithm of 10. */
112#define M_LN10 2.30258509299404568402
113
114/** The constant &pi;. */
115#define M_PI 3.14159265358979323846
116
117/** The constant &pi;/2. */
118#define M_PI_2 1.57079632679489661923
119
120/** The constant &pi;/4. */
121#define M_PI_4 0.78539816339744830962
122
123/** The constant 1/&pi;. */
124#define M_1_PI 0.31830988618379067154
125
126/** The constant 2/&pi;. */
127#define M_2_PI 0.63661977236758134308
128
129/** The constant 2/sqrt(&pi;). */
130#define M_2_SQRTPI 1.12837916709551257390
131
132/** The square root of 2. */
133#define M_SQRT2 1.41421356237309504880
134
135/** The constant \a 1/sqrt(2). */
136#define M_SQRT1_2 0.70710678118654752440
137
138/** The \c double representation of a constant quiet NaN. */
139#define NAN __builtin_nan("")
140
141/** The \c float representation of a constant quiet NaN.
142 \p __tag is a string constant like \c "" or \c "123". */
143#define nanf(__tag) __builtin_nanf(__tag)
144
145/** The \c double representation of a constant quiet NaN.
146 \p __tag is a string constant like \c "" or \c "123". */
147#define nan(__tag) __builtin_nan(__tag)
148
149/** The \c long \c double representation of a constant quiet NaN.
150 \p __tag is a string constant like \c "" or \c "123". */
151#define nanl(__tag) __builtin_nanl(__tag)
152
153/** \c float infinity constant. */
154#define INFINITY __builtin_inff()
155
156/** \c float infinity constant. */
157#define HUGE_VALF __builtin_huge_valf()
158
159/** \c double infinity constant. */
160#define HUGE_VAL __builtin_huge_val()
161
162/** \c long \c double infinity constant. */
163#define HUGE_VALL __builtin_huge_vall()
164
165#include <bits/attribs.h>
166
167/** The cosf() function returns the cosine of \a x, measured in radians. */
168__ATTR_CONST__ extern float cosf (float x);
169/** The cos() function returns the cosine of \a x, measured in radians. */
170__ATTR_CONST__ extern double cos (double x);
171/** The cosl() function returns the cosine of \a x, measured in radians.
172 \since AVR-LibC v2.2 */
173__ATTR_CONST__ extern long double cosl (long double x);
174
175/** The sinf() function returns the sine of \a x, measured in radians. */
176__ATTR_CONST__ extern float sinf (float x);
177/** The sin() function returns the sine of \a x, measured in radians. */
178__ATTR_CONST__ extern double sin (double x);
179/** The sinl() function returns the sine of \a x, measured in radians.
180 \since AVR-LibC v2.2 */
181__ATTR_CONST__ extern long double sinl (long double x);
182
183/** The sincosf() function returns the sine of \a x in \c *psin, and
184 the cosine of \a x in \c *pcos. The angle \a x is measured in radians.
185 A sincosf() call is a bit faster than calling sinf() and cosf()
186 individually, but it consumes a bit more program memory.
187 \since AVR-LibC v2.3 */
188void sincosf (float x, float *psin, float *pcos);
189
190/** The sincos() function returns the sine of \a x in \c *psin, and
191 the cosine of \a x in \c *pcos. The angle \a x is measured in radians.
192 As an example, the performance gain of the IEEE double version of
193 sincos() compared to a sin() plus a cos() call is around 5000 cycles
194 for \a x = 2.0.
195 \since GCC v15.3 (IEEE double), AVR-LibC v2.3 */
196void sincos (double x, double *psin, double *pcos);
197
198/** The sincosl() function returns the sine of \a x in \c *psin, and
199 the cosine of \a x in \c *pcos. The angle \a x is measured in radians.
200 As an example, the performance gain of the IEEE double version of
201 sincosl() compared to a sinl() plus a cosl() call is around 5000 cycles
202 for \a x = 2.0.
203 \since GCC v15.3 (IEEE double), AVR-LibC v2.3 */
204void sincosl (long double x, long double *psin, long double *pcos);
205
206/** The tanf() function returns the tangent of \a x, measured in radians. */
207__ATTR_CONST__ extern float tanf (float x);
208/** The tan() function returns the tangent of \a x, measured in radians. */
209__ATTR_CONST__ extern double tan (double x);
210/** The tanl() function returns the tangent of \a x, measured in radians.
211 \since AVR-LibC v2.2 */
212__ATTR_CONST__ extern long double tanl (long double x);
213
214/** The fabsf() function computes the absolute value of a floating-point
215 number \a x. */
216extern __ATTR_ALWAYS_INLINE__ __ATTR_GNU_INLINE__
217float fabsf (float __x)
218{
219 return __builtin_fabsf (__x);
220}
221
222/** The fabs() function computes the absolute value of a floating-point
223 number \a x. */
224extern __ATTR_ALWAYS_INLINE__ __ATTR_GNU_INLINE__
225double fabs (double __x)
226{
227 return __builtin_fabs (__x);
228}
229
230/** The fabsl() function computes the absolute value of a floating-point
231 number \a x.
232 \since AVR-LibC v2.2 */
233extern __ATTR_ALWAYS_INLINE__ __ATTR_GNU_INLINE__
234long double fabsl (long double __x)
235{
236 return __builtin_fabsl (__x);
237}
238
239/** The function fmodf() returns the floating-point remainder of <em>x / y</em>. */
240__ATTR_CONST__ extern float fmodf (float x, float y);
241/** The function fmod() returns the floating-point remainder of <em>x / y</em>. */
242__ATTR_CONST__ extern double fmod (double x, double y);
243/** The function fmodl() returns the floating-point remainder of <em>x / y</em>.
244 \since AVR-LibC v2.2 */
245__ATTR_CONST__ extern long double fmodl (long double x, long double y);
246
247/** The modff() function breaks the argument \a x into integral and
248 fractional parts, each of which has the same sign as the argument.
249 It stores the integral part as a \c float in the object pointed to by
250 \a iptr.
251
252 The modff() function returns the signed fractional part of \a x.
253
254 \note This implementation skips writing by zero pointer. However,
255 the GCC 4.3 can replace this function with inline code that does not
256 permit to use NULL address for the avoiding of storing. */
257extern float modff (float x, float *iptr);
258/** The modf() function breaks the argument \a x into integral and
259 fractional parts, each of which has the same sign as the argument.
260 It stores the integral part as a \c double in the object pointed to by
261 \a iptr.
262
263 The modf() function returns the signed fractional part of \a x. */
264extern double modf (double x, double *iptr);
265/** The modfl() function breaks the argument \a x into integral and
266 fractional parts, each of which has the same sign as the argument.
267 It stores the integral part as a \c long \c double in the object pointed to by
268 \a iptr.
269
270 The modf() function returns the signed fractional part of \a x.
271 \since AVR-LibC v2.2 */
272extern long double modfl (long double x, long double *iptr);
273
274/** The sqrtf() function returns the non-negative square root of \a x. */
275__ATTR_CONST__ extern float sqrtf (float x);
276/** The sqrt() function returns the non-negative square root of \a x. */
277__ATTR_CONST__ extern double sqrt (double x);
278/** The sqrtl() function returns the non-negative square root of \a x.
279 \since AVR-LibC v2.2 */
280__ATTR_CONST__ extern long double sqrtl (long double x);
281
282/** The cbrtf() function returns the cube root of \a x. */
283__ATTR_CONST__ extern float cbrtf (float x);
284/** The cbrt() function returns the cube root of \a x. */
285__ATTR_CONST__ extern double cbrt (double x);
286/** The cbrtl() function returns the cube root of \a x.
287 \since AVR-LibC v2.2 */
288__ATTR_CONST__ extern long double cbrtl (long double x);
289
290/** The hypotf() function returns <em>sqrtf(x*x + y*y)</em>. This
291 is the length of the hypotenuse of a right triangle with sides of
292 length \a x and \a y, or the distance of the point (\a x, \a
293 y) from the origin. Using this function instead of the direct
294 formula is wise, since the error is much smaller. No underflow with
295 small \a x and \a y. No overflow if result is in range. */
296__ATTR_CONST__ extern float hypotf (float x, float y);
297/** The hypot() function returns <em>sqrt(x*x + y*y)</em>. This
298 is the length of the hypotenuse of a right triangle with sides of
299 length \a x and \a y, or the distance of the point (\a x, \a
300 y) from the origin. Using this function instead of the direct
301 formula is wise, since the error is much smaller. No underflow with
302 small \a x and \a y. No overflow if result is in range. */
303__ATTR_CONST__ extern double hypot (double x, double y);
304/** The hypotl() function returns <em>sqrtl(x*x + y*y)</em>. This
305 is the length of the hypotenuse of a right triangle with sides of
306 length \a x and \a y, or the distance of the point (\a x, \a
307 y) from the origin. Using this function instead of the direct
308 formula is wise, since the error is much smaller. No underflow with
309 small \a x and \a y. No overflow if result is in range.
310 \since AVR-LibC v2.2 */
311__ATTR_CONST__ extern long double hypotl (long double x, long double y);
312
313/** The floorf() function returns the largest integral value less than or
314 equal to \a x, expressed as a floating-point number. */
315__ATTR_CONST__ extern float floorf (float x);
316/** The floor() function returns the largest integral value less than or
317 equal to \a x, expressed as a floating-point number. */
318__ATTR_CONST__ extern double floor (double x);
319/** The floorl() function returns the largest integral value less than or
320 equal to \a x, expressed as a floating-point number.
321 \since AVR-LibC v2.2 */
322__ATTR_CONST__ extern long double floorl (long double x);
323
324/** The ceilf() function returns the smallest integral value greater than
325 or equal to \a x, expressed as a floating-point number. */
326__ATTR_CONST__ extern float ceilf (float x);
327/** The ceil() function returns the smallest integral value greater than
328 or equal to \a x, expressed as a floating-point number. */
329__ATTR_CONST__ extern double ceil (double x);
330/** The ceill() function returns the smallest integral value greater than
331 or equal to \a x, expressed as a floating-point number.
332 \since AVR-LibC v2.2 */
333__ATTR_CONST__ extern long double ceill (long double x);
334
335/** The frexpf() function breaks a floating-point number into a normalized
336 fraction and an integral power of 2. It stores the integer in the \c
337 int object pointed to by \a pexp.
338
339 If \a x is a normal float point number, the frexpf() function
340 returns the value \c v, such that \c v has a magnitude in the
341 interval [1/2, 1) or zero, and \a x equals \c v times 2 raised to
342 the power \a pexp. If \a x is zero, both parts of the result are
343 zero. If \a x is not a finite number, the frexpf() returns \a x as
344 is and stores 0 by \a pexp.
345
346 \note This implementation permits a zero pointer as a directive to
347 skip a storing the exponent.
348 */
349extern float frexpf (float x, int *pexp);
350/** The frexp() function breaks a floating-point number into a normalized
351 fraction and an integral power of 2. It stores the integer in the \c
352 int object pointed to by \a pexp.
353
354 If \a x is a normal float point number, the frexp() function
355 returns the value \c v, such that \c v has a magnitude in the
356 interval [1/2, 1) or zero, and \a x equals \c v times 2 raised to
357 the power \a pexp. If \a x is zero, both parts of the result are
358 zero. If \a x is not a finite number, the frexp() returns \a x as
359 is and stores 0 by \a pexp. */
360extern double frexp (double x, int *pexp);
361/** The frexpl() function breaks a floating-point number into a normalized
362 fraction and an integral power of 2. It stores the integer in the \c
363 int object pointed to by \a pexp.
364
365 If \a x is a normal float point number, the frexpl() function
366 returns the value \c v, such that \c v has a magnitude in the
367 interval [1/2, 1) or zero, and \a x equals \c v times 2 raised to
368 the power \a pexp. If \a x is zero, both parts of the result are
369 zero. If \a x is not a finite number, the frexpl() returns \a x as
370 is and stores 0 by \a pexp.
371 \since AVR-LibC v2.2 */
372extern long double frexpl (long double x, int *pexp);
373
374/** The ldexpf() function multiplies a floating-point number by an integral
375 power of 2. It returns the value of \a x times 2 raised to the power
376 \a iexp. */
377__ATTR_CONST__ extern float ldexpf (float x, int iexp);
378/** The ldexp() function multiplies a floating-point number by an integral
379 power of 2. It returns the value of \a x times 2 raised to the power
380 \a iexp. */
381__ATTR_CONST__ extern double ldexp (double x, int iexp);
382/** The ldexpl() function multiplies a floating-point number by an integral
383 power of 2. It returns the value of \a x times 2 raised to the power
384 \a iexp.
385 \since AVR-LibC v2.2 */
386__ATTR_CONST__ extern long double ldexpl (long double x, int iexp);
387
388/** The expf() function returns the exponential value of \a x. */
389__ATTR_CONST__ extern float expf (float x);
390/** The exp() function returns the exponential value of \a x. */
391__ATTR_CONST__ extern double exp (double x);
392/** The expl() function returns the exponential value of \a x.
393 \since AVR-LibC v2.2 */
394__ATTR_CONST__ extern long double expl (long double x);
395
396/** The coshf() function returns the hyperbolic cosine of \a x. */
397__ATTR_CONST__ extern float coshf (float x);
398/** The cosh() function returns the hyperbolic cosine of \a x. */
399__ATTR_CONST__ extern double cosh (double x);
400/** The coshl() function returns the hyperbolic cosine of \a x.
401 \since AVR-LibC v2.2 */
402__ATTR_CONST__ extern long double coshl (long double x);
403
404/** The sinhf() function returns the hyperbolic sine of \a x. */
405__ATTR_CONST__ extern float sinhf (float x);
406/** The sinh() function returns the hyperbolic sine of \a x. */
407__ATTR_CONST__ extern double sinh (double x);
408/** The sinhl() function returns the hyperbolic sine of \a x. */
409__ATTR_CONST__ extern long double sinhl (long double x);
410
411/** The tanhf() function returns the hyperbolic tangent of \a x. */
412__ATTR_CONST__ extern float tanhf (float x);
413/** The tanh() function returns the hyperbolic tangent of \a x. */
414__ATTR_CONST__ extern double tanh (double x);
415/** The tanhl() function returns the hyperbolic tangent of \a x.
416 \since AVR-LibC v2.2 */
417__ATTR_CONST__ extern long double tanhl (long double x);
418
419/** The acosf() function computes the principal value of the arc cosine of
420 \a x. The returned value is in the range [0, &pi;] radians. A domain
421 error occurs for arguments not in the range [&minus;1, +1].
422 The relative error is bounded by 1.9&middot;10<sup>&minus;7</sup>. */
423__ATTR_CONST__ extern float acosf (float x);
424/** The acos() function computes the principal value of the arc cosine of
425 \a x. The returned value is in the range [0, &pi;] radians or NaN. */
426__ATTR_CONST__ extern double acos (double x);
427/** The acosl() function computes the principal value of the arc cosine of
428 \a x. The returned value is in the range [0, &pi;] radians or NaN.
429 \since AVR-LibC v2.2 */
430__ATTR_CONST__ extern long double acosl (long double x);
431
432/** The asinf() function computes the principal value of the arc sine of \a x.
433 The returned value is in the range [&minus;&pi;/2, &pi;/2] radians. A
434 domain error occurs for arguments not in the range [&minus;1, +1].
435 The relative error is bounded by 3.3&middot;10<sup>&minus;7</sup>. */
436__ATTR_CONST__ extern float asinf (float x);
437/** The asin() function computes the principal value of the arc sine of \a x.
438 The returned value is in the range [&minus;&pi;/2, &pi;/2] radians or NaN.*/
439__ATTR_CONST__ extern double asin (double x);
440/** The asinl() function computes the principal value of the arc sine of \a x.
441 The returned value is in the range [&minus;&pi;/2, &pi;/2] radians or NaN.
442 \since AVR-LibC v2.2 */
443__ATTR_CONST__ extern long double asinl (long double x);
444
445/** The atanf() function computes the principal value of the arc tangent
446 of \a x. The returned value is in the range [&minus;&pi;/2, &pi;/2] radians.
447 The relative error is bounded by 1.3&middot;10<sup>&minus;7</sup>. */
448__ATTR_CONST__ extern float atanf (float x);
449/** The atan() function computes the principal value of the arc tangent of \a x.
450 The returned value is in the range [&minus;&pi;/2, &pi;/2] radians. */
451__ATTR_CONST__ extern double atan (double x);
452/** The atanl() function computes the principal value of the arc tangent of
453 \a x. The returned value is in the range [&minus;&pi;/2, &pi;/2] radians.
454 \since AVR-LibC v2.2 */
455__ATTR_CONST__ extern long double atanl (long double x);
456
457/** The atan2f() function computes the principal value of the arc tangent
458 of <em>y / x</em>, using the signs of both arguments to determine
459 the quadrant of the return value. The returned value is in the range
460 [&minus;&pi;, +&pi;] radians. */
461__ATTR_CONST__ extern float atan2f (float y, float x);
462/** The atan2() function computes the principal value of the arc tangent
463 of <em>y / x</em>, using the signs of both arguments to determine
464 the quadrant of the return value. The returned value is in the range
465 [&minus;&pi;, +&pi;] radians. */
466__ATTR_CONST__ extern double atan2 (double y, double x);
467/** The atan2l() function computes the principal value of the arc tangent
468 of <em>y / x</em>, using the signs of both arguments to determine
469 the quadrant of the return value. The returned value is in the range
470 [&minus;&pi;, +&pi;] radians.
471 \since AVR-LibC v2.2 */
472__ATTR_CONST__ extern long double atan2l (long double y, long double x);
473
474/** The logf() function returns the natural logarithm of argument \a x.
475 The relative error is bounded by 2.3&middot;10<sup>&minus;7</sup>. */
476__ATTR_CONST__ extern float logf (float x);
477/** The log() function returns the natural logarithm of argument \a x. */
478__ATTR_CONST__ extern double log (double x);
479/** The logl() function returns the natural logarithm of argument \a x.
480 \since AVR-LibC v2.2 */
481__ATTR_CONST__ extern long double logl (long double x);
482
483/** The log10f() function returns the logarithm of argument \a x to base 10.
484 The relative error is bounded by 2.8&middot;10<sup>&minus;7</sup>. */
485__ATTR_CONST__ extern float log10f (float x);
486/** The log10() function returns the logarithm of argument \a x to base 10. */
487__ATTR_CONST__ extern double log10 (double x);
488/** The log10l() function returns the logarithm of argument \a x to base 10.
489 \since AVR-LibC v2.2 */
490__ATTR_CONST__ extern long double log10l (long double x);
491
492/** The log2f() function returns the logarithm of argument \a x to base 2.
493 The relative error is bounded by 1.8&middot;10<sup>&minus;7</sup>.
494 \since AVR-LibC v2.3 */
495__ATTR_CONST__ extern float log2f (float x);
496/** The log2() function returns the logarithm of argument \a x to base 2.
497 \since AVR-LibC v2.3 */
498__ATTR_CONST__ extern double log2 (double x);
499/** The log2l() function returns the logarithm of argument \a x to base 2.
500 \since AVR-LibC v2.3 */
501__ATTR_CONST__ extern long double log2l (long double x);
502
503/** The function powf() returns the value of \a x to the exponent \a y.
504 \n Notice that for integer exponents, there is the more efficient
505 <code>float __builtin_powif(float x, int y)</code>. */
506__ATTR_CONST__ extern float powf (float x, float y);
507/** The function pow() returns the value of \a x to the exponent \a y.
508 \n Notice that for integer exponents, there is the more efficient
509 <code>double __builtin_powi(double x, int y)</code>. */
510__ATTR_CONST__ extern double pow (double x, double y);
511/** The function powl() returns the value of \a x to the exponent \a y.
512 \n Notice that for integer exponents, there is the more efficient
513 <code>long double __builtin_powil(long double x, int y)</code>.
514 \since AVR-LibC v2.2 */
515__ATTR_CONST__ extern long double powl (long double x, long double y);
516
517/** The function isnanf() returns 1 if the argument \a x represents a
518 "not-a-number" (NaN) object, otherwise 0. */
519__ATTR_CONST__ extern int isnanf (float x);
520/** The function isnan() returns 1 if the argument \a x represents a
521 "not-a-number" (NaN) object, otherwise 0. */
522__ATTR_CONST__ extern int isnan (double x);
523/** The function isnanl() returns 1 if the argument \a x represents a
524 "not-a-number" (NaN) object, otherwise 0.
525 \since AVR-LibC v2.2 */
526__ATTR_CONST__ extern int isnanl (long double x);
527
528/** The function isinff() returns 1 if the argument \a x is positive
529 infinity, &minus;1 if \a x is negative infinity, and 0 otherwise. */
530__ATTR_CONST__ extern int isinff (float x);
531/** The function isinf() returns 1 if the argument \a x is positive
532 infinity, &minus;1 if \a x is negative infinity, and 0 otherwise. */
533__ATTR_CONST__ extern int isinf (double x);
534/** The function isinfl() returns 1 if the argument \a x is positive
535 infinity, &minus;1 if \a x is negative infinity, and 0 otherwise.
536 \since AVR-LibC v2.2 */
537__ATTR_CONST__ extern int isinfl (long double x);
538
539/** The isfinitef() function returns a nonzero value if \a __x is finite:
540 not plus or minus infinity, and not NaN. */
541__ATTR_CONST__ static __ATTR_ALWAYS_INLINE__ int isfinitef (float __x)
542{
543 unsigned char __exp;
544 __asm__ (
545 "mov %0, %C1" "\n\t"
546 "lsl %0" "\n\t"
547 "mov %0, %D1" "\n\t"
548 "rol %0"
549 : "=&r" (__exp)
550 : "r" (__x) );
551 return __exp != 0xff;
552}
553
554/** The isfinite() function returns a nonzero value if \a __x is finite:
555 not plus or minus infinity, and not NaN. */
556#ifdef __DOXYGEN__
557static __ATTR_ALWAYS_INLINE__ int isfinite (double __x);
558#elif __SIZEOF_DOUBLE__ == __SIZEOF_FLOAT__
559static __ATTR_ALWAYS_INLINE__ int isfinite (double __x)
560{
561 return isfinitef (__x);
562}
563#else
564int isfinite (double __x);
565#endif /* double = float */
566
567/** The isfinitel() function returns a nonzero value if \a __x is finite:
568 not plus or minus infinity, and not NaN.
569 \since AVR-LibC v2.2 */
570#ifdef __DOXYGEN__
571static __ATTR_ALWAYS_INLINE__ int isfinitel (long double __x);
572#elif __SIZEOF_LONG_DOUBLE__ == __SIZEOF_FLOAT__
573static __ATTR_ALWAYS_INLINE__ int isfinitel (long double __x)
574{
575 return isfinitef (__x);
576}
577#else
578int isfinitel (long double __x);
579#endif /* long double = float */
580
581/** The copysignf() function returns \a __x but with the sign of \a __y.
582 They work even if \a __x or \a __y are NaN or zero. */
583__ATTR_CONST__ static __ATTR_ALWAYS_INLINE__ float copysignf (float __x, float __y)
584{
585 __asm__ (
586 "bst %D2, 7" "\n\t"
587 "bld %D0, 7"
588 : "=r" (__x)
589 : "0" (__x), "r" (__y));
590 return __x;
591}
592
593/** The copysign() function returns \a __x but with the sign of \a __y.
594 They work even if \a __x or \a __y are NaN or zero. */
595__ATTR_CONST__ static __ATTR_ALWAYS_INLINE__ double copysign (double __x, double __y)
596{
597 __asm__ (
598 "bst %r1+%2-1, 7" "\n\t"
599 "bld %r0+%2-1, 7"
600 : "+r" (__x)
601 : "r" (__y), "n" (__SIZEOF_DOUBLE__));
602 return __x;
603}
604
605/** The copysignl() function returns \a __x but with the sign of \a __y.
606 They work even if \a __x or \a __y are NaN or zero.
607 \since AVR-LibC v2.2 */
608__ATTR_CONST__ static __ATTR_ALWAYS_INLINE__ long double copysignl (long double __x, long double __y)
609{
610 __asm__ (
611 "bst %r1+%2-1, 7" "\n\t"
612 "bld %r0+%2-1, 7"
613 : "+r" (__x)
614 : "r" (__y), "n" (__SIZEOF_LONG_DOUBLE__));
615 return __x;
616}
617
618/** The signbitf() function returns a nonzero value if the value of \a x
619 has its sign bit set. This is not the same as `\a x < 0.0',
620 because IEEE 754 floating point allows zero to be signed. The
621 comparison '&minus;0.0 < 0.0' is false, but `signbit (&minus;0.0)'
622 will return a nonzero value. */
623__ATTR_CONST__ extern int signbitf (float x);
624/** The signbit() function returns a nonzero value if the value of \a x
625 has its sign bit set. This is not the same as `\a x < 0.0',
626 because IEEE 754 floating point allows zero to be signed. The
627 comparison '&minus;0.0 < 0.0' is false, but `signbit (&minus;0.0)'
628 will return a nonzero value. */
629__ATTR_CONST__ extern int signbit (double x);
630/** The signbitl() function returns a nonzero value if the value of \a x
631 has its sign bit set. This is not the same as `\a x < 0.0',
632 because IEEE 754 floating point allows zero to be signed. The
633 comparison '&minus;0.0 < 0.0' is false, but `signbit (&minus;0.0)'
634 will return a nonzero value.
635 \since AVR-LibC v2.2 */
636__ATTR_CONST__ extern int signbitl (long double x);
637
638/** The fdimf() function returns <em>max(x &minus; y, 0)</em>. If \a x or
639 \a y or both are NaN, NaN is returned. */
640__ATTR_CONST__ extern float fdimf (float x, float y);
641/** The fdim() function returns <em>max(x &minus; y, 0)</em>. If \a x or
642 \a y or both are NaN, NaN is returned. */
643__ATTR_CONST__ extern double fdim (double x, double y);
644/** The fdiml() function returns <em>max(x &minus; y, 0)</em>. If \a x or
645 \a y or both are NaN, NaN is returned.
646 \since AVR-LibC v2.2, GCC v15.2 */
647__ATTR_CONST__ extern long double fdiml (long double x, long double y);
648
649/** The fmaf() function performs floating-point multiply-add. This is the
650 operation <em>(x * y) + z</em>, but the intermediate result is
651 not rounded to the destination type. This can sometimes improve the
652 precision of a calculation. */
653__ATTR_CONST__ extern float fmaf (float x, float y, float z);
654/** The fma() function performs floating-point multiply-add. This is the
655 operation <em>(x * y) + z</em>, but the intermediate result is
656 not rounded to the destination type. This can sometimes improve the
657 precision of a calculation. */
658__ATTR_CONST__ extern double fma (double x, double y, double z);
659/** The fmal() function performs floating-point multiply-add. This is the
660 operation <em>(x * y) + z</em>, but the intermediate result is
661 not rounded to the destination type. This can sometimes improve the
662 precision of a calculation.
663 \since AVR-LibC v2.2 */
664__ATTR_CONST__ extern long double fmal (long double x, long double y, long double z);
665
666/** The fmaxf() function returns the greater of the two values \a x and
667 \a y. If an argument is NaN, the other argument is returned. If
668 both arguments are NaN, NaN is returned. */
669__ATTR_CONST__ extern float fmaxf (float x, float y);
670/** The fmax() function returns the greater of the two values \a x and
671 \a y. If an argument is NaN, the other argument is returned. If
672 both arguments are NaN, NaN is returned. */
673__ATTR_CONST__ extern double fmax (double x, double y);
674/** The fmaxl() function returns the greater of the two values \a x and
675 \a y. If an argument is NaN, the other argument is returned. If
676 both arguments are NaN, NaN is returned.
677 \since AVR-LibC v2.2 */
678__ATTR_CONST__ extern long double fmaxl (long double x, long double y);
679
680/** The fminf() function returns the lesser of the two values \a x and
681 \a y. If an argument is NaN, the other argument is returned. If
682 both arguments are NaN, NaN is returned. */
683__ATTR_CONST__ extern float fminf (float x, float y);
684/** The fmin() function returns the lesser of the two values \a x and
685 \a y. If an argument is NaN, the other argument is returned. If
686 both arguments are NaN, NaN is returned. */
687__ATTR_CONST__ extern double fmin (double x, double y);
688/** The fminl() function returns the lesser of the two values \a x and
689 \a y. If an argument is NaN, the other argument is returned. If
690 both arguments are NaN, NaN is returned.
691 \since AVR-LibC v2.2 */
692__ATTR_CONST__ extern long double fminl (long double x, long double y);
693
694/** The truncf() function rounds \a x to the nearest integer not larger
695 in absolute value. */
696__ATTR_CONST__ extern float truncf (float x);
697/** The trunc() function rounds \a x to the nearest integer not larger
698 in absolute value. */
699__ATTR_CONST__ extern double trunc (double x);
700/** The truncl() function rounds \a x to the nearest integer not larger
701 in absolute value.
702 \since AVR-LibC v2.2 */
703__ATTR_CONST__ extern long double truncl (long double x);
704
705/** The roundf() function rounds \a x to the nearest integer, but rounds
706 halfway cases away from zero (instead of to the nearest even integer).
707 Overflow is impossible.
708
709 \return The rounded value. If \a x is an integral or infinite, \a
710 x itself is returned. If \a x is \c NaN, then \c NaN is returned. */
711__ATTR_CONST__ extern float roundf (float x);
712/** The round() function rounds \a x to the nearest integer, but rounds
713 halfway cases away from zero (instead of to the nearest even integer).
714 Overflow is impossible.
715
716 \return The rounded value. If \a x is an integral or infinite, \a
717 x itself is returned. If \a x is \c NaN, then \c NaN is returned. */
718__ATTR_CONST__ extern double round (double x);
719/** The roundl() function rounds \a x to the nearest integer, but rounds
720 halfway cases away from zero (instead of to the nearest even integer).
721 Overflow is impossible.
722
723 \return The rounded value. If \a x is an integral or infinite, \a
724 x itself is returned. If \a x is \c NaN, then \c NaN is returned.
725 \since AVR-LibC v2.2 */
726__ATTR_CONST__ extern long double roundl (long double x);
727
728/** The lroundf() function rounds \a x to the nearest integer, but rounds
729 halfway cases away from zero (instead of to the nearest even integer).
730 This function is similar to round() function, but it differs in type of
731 return value and in that an overflow is possible.
732
733 \return The rounded long integer value. If \a x is not a finite number
734 or an overflow was, this realization returns the \c LONG_MIN value
735 (0x80000000). */
736__ATTR_CONST__ extern long lroundf (float x);
737/** The lround() function rounds \a x to the nearest integer, but rounds
738 halfway cases away from zero (instead of to the nearest even integer).
739 This function is similar to round() function, but it differs in type of
740 return value and in that an overflow is possible.
741
742 \return The rounded long integer value. If \a x is not a finite number
743 or an overflow was, this realization returns the \c LONG_MIN value
744 (0x80000000). */
745__ATTR_CONST__ extern long lround (double x);
746/** The lroundl() function rounds \a x to the nearest integer, but rounds
747 halfway cases away from zero (instead of to the nearest even integer).
748 This function is similar to round() function, but it differs in type of
749 return value and in that an overflow is possible.
750
751 \return The rounded long integer value. If \a x is not a finite number
752 or an overflow was, this realization returns the \c LONG_MIN value
753 (0x80000000).
754 \since AVR-LibC v2.2 */
755__ATTR_CONST__ extern long lroundl (long double x);
756
757/** The lrintf() function rounds \a x to the nearest integer, rounding the
758 halfway cases to the even integer direction. (That is both 1.5 and 2.5
759 values are rounded to 2). This function is similar to rintf() function,
760 but it differs in type of return value and in that an overflow is
761 possible.
762
763 \return The rounded long integer value. If \a x is not a finite
764 number or an overflow was, this realization returns the \c LONG_MIN
765 value (0x80000000). */
766__ATTR_CONST__ extern long lrintf (float x);
767/** The lrint() function rounds \a x to the nearest integer, rounding the
768 halfway cases to the even integer direction. (That is both 1.5 and 2.5
769 values are rounded to 2). This function is similar to rint() function,
770 but it differs in type of return value and in that an overflow is
771 possible.
772
773 \return The rounded long integer value. If \a x is not a finite
774 number or an overflow was, this realization returns the \c LONG_MIN
775 value (0x80000000). */
776__ATTR_CONST__ extern long lrint (double x);
777/** The lrintl() function rounds \a x to the nearest integer, rounding the
778 halfway cases to the even integer direction. (That is both 1.5 and 2.5
779 values are rounded to 2). This function is similar to rintl() function,
780 but it differs in type of return value and in that an overflow is
781 possible.
782
783 \return The rounded long integer value. If \a x is not a finite
784 number or an overflow was, this realization returns the \c LONG_MIN
785 value (0x80000000).
786 \since AVR-LibC v2.2 */
787__ATTR_CONST__ extern long lrintl (long double x);
788
789/**@}*/
790
791/**@{*/
792/**
793 \name Non-Standard Math Functions
794*/
795
796/** \ingroup avr_math
797 The function squaref() returns <em>x * x</em>.
798 \note This function does not belong to the C standard definition. */
799__ATTR_CONST__ extern float squaref (float x);
800
801/** The function square() returns <em>x * x</em>.
802 \note This function does not belong to the C standard definition. */
803
804#if defined(__DOXYGEN__) || __SIZEOF_DOUBLE__ == __SIZEOF_FLOAT__
805__ATTR_CONST__ extern double square (double x);
806#elif defined(__WITH_LIBF7_MATH__)
807__ATTR_CONST__ extern double square (double x) __asm("__f7_square");
808#endif
809
810/** The function squarel() returns <em>x * x</em>.
811 \note This function does not belong to the C standard definition.
812 \since AVR-LibC v2.2 */
813#if defined(__DOXYGEN__) || __SIZEOF_LONG_DOUBLE__ == __SIZEOF_FLOAT__
814__ATTR_CONST__ extern long double squarel (long double x);
815#elif defined(__WITH_LIBF7_MATH__)
816__ATTR_CONST__ extern long double squarel (long double x) __asm("__f7_square");
817#endif
818
819/**@}*/
820
821#ifdef __cplusplus
822}
823#endif
824
825#endif /* !__MATH_H */
double fabs(double __x)
Definition: math.h:225
float floorf(float x)
float expf(float x)
long double fmaxl(long double x, long double y)
long double ldexpl(long double x, int iexp)
long double squarel(long double x)
long lrint(double x)
int signbitf(float x)
float sinhf(float x)
double atan(double x)
double ceil(double x)
long double floorl(long double x)
long double tanl(long double x)
long double powl(long double x, long double y)
void sincosl(long double x, long double *psin, long double *pcos)
double atan2(double y, double x)
double fmax(double x, double y)
double cosh(double x)
double log2(double x)
float cbrtf(float x)
long double asinl(long double x)
static int isfinitef(float __x)
Definition: math.h:541
double ldexp(double x, int iexp)
double square(double x)
int isinfl(long double x)
float squaref(float x)
float sqrtf(float x)
float coshf(float x)
long double frexpl(long double x, int *pexp)
int isnanl(long double x)
long double cbrtl(long double x)
double fmod(double x, double y)
long double coshl(long double x)
int isinff(float x)
static int isfinitel(long double __x)
double cos(double x)
float fabsf(float __x)
Definition: math.h:217
long double atanl(long double x)
long double roundl(long double x)
double log10(double x)
long double cosl(long double x)
float tanf(float x)
double hypot(double x, double y)
double floor(double x)
long lrintf(float x)
float asinf(float x)
float tanhf(float x)
int signbitl(long double x)
float log2f(float x)
float cosf(float x)
double round(double x)
double fdim(double x, double y)
float logf(float x)
double trunc(double x)
long lrintl(long double x)
int isinf(double x)
double sinh(double x)
float fmaxf(float x, float y)
int signbit(double x)
long double fminl(long double x, long double y)
float sinf(float x)
double cbrt(double x)
float ceilf(float x)
long double truncl(long double x)
double frexp(double x, int *pexp)
long double hypotl(long double x, long double y)
long double tanhl(long double x)
float acosf(float x)
float fminf(float x, float y)
long double sqrtl(long double x)
float hypotf(float x, float y)
long double log2l(long double x)
double tan(double x)
double pow(double x, double y)
float atanf(float x)
float fmaf(float x, float y, float z)
long double fabsl(long double __x)
Definition: math.h:234
float truncf(float x)
float frexpf(float x, int *pexp)
long double fmodl(long double x, long double y)
double asin(double x)
long double atan2l(long double y, long double x)
float ldexpf(float x, int iexp)
double sin(double x)
static double copysign(double __x, double __y)
Definition: math.h:595
double sqrt(double x)
long double fdiml(long double x, long double y)
long double modfl(long double x, long double *iptr)
float powf(float x, float y)
double fma(double x, double y, double z)
static float copysignf(float __x, float __y)
Definition: math.h:583
long double sinhl(long double x)
float modff(float x, float *iptr)
double log(double x)
long lround(double x)
float roundf(float x)
double exp(double x)
long double ceill(long double x)
int isnanf(float x)
float log10f(float x)
long double log10l(long double x)
long double acosl(long double x)
double acos(double x)
long lroundl(long double x)
long double sinl(long double x)
long double expl(long double x)
static long double copysignl(long double __x, long double __y)
Definition: math.h:608
float fdimf(float x, float y)
double fmin(double x, double y)
float fmodf(float x, float y)
long double fmal(long double x, long double y, long double z)
long double logl(long double x)
void sincos(double x, double *psin, double *pcos)
double tanh(double x)
float atan2f(float y, float x)
static int isfinite(double __x)
double modf(double x, double *iptr)
void sincosf(float x, float *psin, float *pcos)
int isnan(double x)
long lroundf(float x)