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