AVR-LibC  2.3.0git
Standard C library for AVR-GCC
 

AVR-LibC Documen­tation

AVR-LibC Development Pages

Main Page

User Manual

Library Refe­rence

FAQ

Example Projects

File List

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