AVR-LibC  2.2.0
Standard C library for AVR-GCC
 

AVR-LibC Documentation

Logo

AVR-LibC Development Pages

Main Page

User Manual

Library Reference

FAQ

Example Projects

File List

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