File: math.h

package info (click to toggle)
avr-libc 1%3A2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 147,748 kB
  • sloc: ansic: 813,422; asm: 8,821; sh: 2,194; cpp: 1,483; python: 1,437; makefile: 659; perl: 509; pascal: 500
file content (740 lines) | stat: -rw-r--r-- 33,728 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
/* Copyright (c) 2002,2007-2009 Michael Stumpf

   Portions of documentation Copyright (c) 1990 - 1994
   The Regents of the University of California.

   All rights reserved.

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions are met:

   * Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.

   * Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in
     the documentation and/or other materials provided with the
     distribution.

   * Neither the name of the copyright holders nor the names of
     contributors may be used to endorse or promote products derived
     from this software without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  POSSIBILITY OF SUCH DAMAGE. */

/* $Id$ */

/*
   math.h - mathematical functions

   Author : Michael Stumpf
            Michael.Stumpf@t-online.de

   __ATTR_CONST__ added by marekm@linux.org.pl for functions
   that "do not examine any values except their arguments, and have
   no effects except the return value", for better optimization by gcc.
 */

#ifndef __MATH_H
#define __MATH_H

#ifdef __cplusplus
extern "C" {
#endif

/** \file */
/** \defgroup avr_math <math.h>: Mathematics
    \code #include <math.h> \endcode

    This header file declares basic mathematics constants and
    functions.

    \par Notes:
    - Math functions do not raise exceptions and do not change the
      \c errno variable. Therefore the majority of them are declared
      with \c const attribute, for better optimization by GCC.
    - 64-bit floating-point arithmetic is only available in
      <a href="https://gcc.gnu.org/gcc-10/changes.html#avr">avr-gcc v10</a>
      and up.
      The size of the \c double and \c long \c double type can be selected
      at compile-time with options like <tt>-mdouble=64</tt> and
      <tt>-mlong-double=32</tt>.  Whether such options are available,
      and their default values,
      depend on how the compiler has been configured.
    - The implementation of 64-bit floating-point arithmetic has some
      shortcomings and limitations, see the
      <a href="https://gcc.gnu.org/wiki/avr-gcc#Libf7">avr-gcc Wiki</a>
      for details.
    - In order to access the <tt>float</tt> functions,
      in avr-gcc v4.6 and older it is usually
      also required to link with \c -lm. In avr-gcc v4.7 and up, \c -lm
      is added automatically to all linker invocations.
*/


/** \ingroup avr_math */
/**@{*/

/** The constant Euler's number \a e. */
#define M_E 2.7182818284590452354

/** The constant logarithm of Euler's number \a e to base 2. */
#define M_LOG2E 1.4426950408889634074

/** The constant logarithm of Euler's number \a e to base 10. */
#define M_LOG10E	0.43429448190325182765

/** The constant natural logarithm of 2.	*/
#define M_LN2		0.69314718055994530942

/** The constant natural logarithm of 10.	*/
#define M_LN10		2.30258509299404568402

/** The constant \a pi.	*/
#define M_PI		3.14159265358979323846

/** The constant \a pi/2.	*/
#define M_PI_2		1.57079632679489661923

/** The constant \a pi/4.	*/
#define M_PI_4		0.78539816339744830962

/** The constant \a 1/pi.	*/
#define M_1_PI		0.31830988618379067154

/** The constant \a 2/pi.	*/
#define M_2_PI		0.63661977236758134308

/** The constant \a 2/sqrt(pi).	*/
#define M_2_SQRTPI	1.12837916709551257390

/** The square root of 2.	*/
#define M_SQRT2		1.41421356237309504880

/** The constant \a 1/sqrt(2).	*/
#define M_SQRT1_2	0.70710678118654752440

/** The \c double representation of a constant quiet NaN. */
#define NAN	__builtin_nan("")

/** The \c float representation of a constant quiet NaN.
    \p __tag is a string constant like \c "" or \c "123". */
#define nanf(__tagp)	__builtin_nanf(__tag)

/** The \c double representation of a constant quiet NaN.
    \p __tag is a string constant like \c "" or \c "123". */
#define nan(__tag)	__builtin_nan(__tag)

/** The \c long \c double representation of a constant quiet NaN.
    \p __tag is a string constant like \c "" or \c "123". */
#define nanl(__tag)	__builtin_nanl(__tag)

/** \c double infinity constant.	*/
#define INFINITY __builtin_inf()

/** \c float infinity constant.	*/
#define HUGE_VALF __builtin_huge_valf()

/** \c double infinity constant.	*/
#define HUGE_VAL __builtin_huge_val()

/** \c long \c double infinity constant.	*/
#define HUGE_VALL __builtin_huge_vall()

#ifndef __DOXYGEN__
#ifndef  __ATTR_CONST__
# define __ATTR_CONST__ __attribute__((__const__))
#endif

#ifndef __ATTR_ALWAYS_INLINE__
#define __ATTR_ALWAYS_INLINE__ __inline__ __attribute__((__always_inline__))
#endif
#endif /* ! DOXYGEN */

/** The cosf() function returns the cosine of \a x, measured in radians. */
__ATTR_CONST__ extern float cosf (float x);
/** The cos() function returns the cosine of \a x, measured in radians. */
__ATTR_CONST__ extern double cos (double x);
/** The cosl() function returns the cosine of \a x, measured in radians. */
__ATTR_CONST__ extern long double cosl (long double x);

/** The sinf() function returns the sine of \a x, measured in radians. */
__ATTR_CONST__ extern float sinf (float x);
/** The sin() function returns the sine of \a x, measured in radians. */
__ATTR_CONST__ extern double sin (double x);
/** The sinl() function returns the sine of \a x, measured in radians. */
__ATTR_CONST__ extern long double sinl (long double x);

/** The tanf() function returns the tangent of \a x, measured in radians. */
__ATTR_CONST__ extern float tanf (float x);
/** The tan() function returns the tangent of \a x, measured in radians. */
__ATTR_CONST__ extern double tan (double x);
/** The tanl() function returns the tangent of \a x, measured in radians. */
__ATTR_CONST__ extern long double tanl (long double x);

/** The fabsf() function computes the absolute value of a floating-point number \a x. */
static __ATTR_ALWAYS_INLINE__ float fabsf (float __x)
{
    return __builtin_fabsf (__x);
}

/** The fabs() function computes the absolute value of a floating-point number \a x. */
static __ATTR_ALWAYS_INLINE__ double fabs (double __x)
{
    return __builtin_fabs (__x);
}

/** The fabsl() function computes the absolute value of a floating-point number \a x. */
static __ATTR_ALWAYS_INLINE__ long double fabsl (long double __x)
{
    return __builtin_fabsl (__x);
}

/** The function fmodf() returns the floating-point remainder of <em>x / y</em>. */
__ATTR_CONST__ extern float fmodf (float x, float y);
/** The function fmod() returns the floating-point remainder of <em>x / y</em>. */
__ATTR_CONST__ extern double fmod (double x, double y);
/** The function fmodl() returns the floating-point remainder of <em>x / y</em>. */
__ATTR_CONST__ extern long double fmodl (long double x, long double y);

/** The modff() function breaks the argument \a x into integral and
    fractional parts, each of which has the same sign as the argument.
    It stores the integral part as a \c float in the object pointed to by
    \a iptr.

    The modff() function returns the signed fractional part of \a x.

    \note This implementation skips writing by zero pointer.  However,
    the GCC 4.3 can replace this function with inline code that does not
    permit to use NULL address for the avoiding of storing. */
extern float modff (float x, float *iptr);
/** The modf() function breaks the argument \a x into integral and
    fractional parts, each of which has the same sign as the argument.
    It stores the integral part as a \c double in the object pointed to by
    \a iptr.

    The modf() function returns the signed fractional part of \a x. */
extern double modf (double x, double *iptr);
/** The modfl() function breaks the argument \a x into integral and
    fractional parts, each of which has the same sign as the argument.
    It stores the integral part as a \c long \c double in the object pointed to by
    \a iptr.

    The modf() function returns the signed fractional part of \a x. */
extern long double modfl (long double x, long double *iptr);

/** The sqrtf() function returns the non-negative square root of \a x. */
__ATTR_CONST__ extern float sqrtf (float x);
/** The sqrt() function returns the non-negative square root of \a x. */
__ATTR_CONST__ extern double sqrt (double x);
/** The sqrtl() function returns the non-negative square root of \a x. */
__ATTR_CONST__ extern long double sqrtl (long double x);

/** The cbrtf() function returns the cube root of \a x. */
__ATTR_CONST__ extern float cbrtf (float x);
/** The cbrt() function returns the cube root of \a x. */
__ATTR_CONST__ extern double cbrt (double x);
/** The cbrtl() function returns the cube root of \a x. */
__ATTR_CONST__ extern long double cbrtl (long double x);

/** The hypotf() function returns <em>sqrtf(x*x + y*y)</em>. This
    is the length of the hypotenuse of a right triangle with sides of
    length \a x and \a y, or the  distance of the point (\a x, \a
    y) from the origin. Using this function  instead of the direct
    formula is wise, since the error is much smaller. No underflow with
    small \a x and \a y. No overflow if result is in range. */
__ATTR_CONST__ extern float hypotf (float x, float y);
/** The hypot() function returns <em>sqrt(x*x + y*y)</em>. This
    is the length of the hypotenuse of a right triangle with sides of
    length \a x and \a y, or the  distance of the point (\a x, \a
    y) from the origin. Using this function  instead of the direct
    formula is wise, since the error is much smaller. No underflow with
    small \a x and \a y. No overflow if result is in range. */
__ATTR_CONST__ extern double hypot (double x, double y);
/** The hypotl() function returns <em>sqrtl(x*x + y*y)</em>. This
    is the length of the hypotenuse of a right triangle with sides of
    length \a x and \a y, or the  distance of the point (\a x, \a
    y) from the origin. Using this function  instead of the direct
    formula is wise, since the error is much smaller. No underflow with
    small \a x and \a y. No overflow if result is in range. */
__ATTR_CONST__ extern long double hypotl (long double x, long double y);

/** The floorf() function returns the largest integral value less than or
    equal to \a x, expressed as a floating-point number. */
__ATTR_CONST__ extern float floorf (float x);
/** The floor() function returns the largest integral value less than or
    equal to \a x, expressed as a floating-point number. */
__ATTR_CONST__ extern double floor (double x);
/** The floorl() function returns the largest integral value less than or
    equal to \a x, expressed as a floating-point number. */
__ATTR_CONST__ extern long double floorl (long double x);

/** The ceilf() function returns the smallest integral value greater than
    or equal to \a x, expressed as a floating-point number. */
__ATTR_CONST__ extern float ceilf (float x);
/** The ceil() function returns the smallest integral value greater than
    or equal to \a x, expressed as a floating-point number. */
__ATTR_CONST__ extern double ceil (double x);
/** The ceill() function returns the smallest integral value greater than
    or equal to \a x, expressed as a floating-point number. */
__ATTR_CONST__ extern long double ceill (long double x);

/** The frexpf() function breaks a floating-point number into a normalized
    fraction and an integral power of 2.  It stores the integer in the \c
    int object pointed to by \a pexp.

    If \a x is a normal float point number, the frexpf() function
    returns the value \c v, such that \c v has a magnitude in the
    interval [1/2, 1) or zero, and \a x equals \c v times 2 raised to
    the power \a pexp. If \a x is zero, both parts of the result are
    zero. If \a x is not a finite number, the frexpf() returns \a x as
    is and stores 0 by \a pexp.

    \note  This implementation permits a zero pointer as a directive to
    skip a storing the exponent.
 */
extern float frexpf (float x, int *pexp);
/** The frexp() function breaks a floating-point number into a normalized
    fraction and an integral power of 2.  It stores the integer in the \c
    int object pointed to by \a pexp.

    If \a x is a normal float point number, the frexp() function
    returns the value \c v, such that \c v has a magnitude in the
    interval [1/2, 1) or zero, and \a x equals \c v times 2 raised to
    the power \a pexp. If \a x is zero, both parts of the result are
    zero. If \a x is not a finite number, the frexp() returns \a x as
    is and stores 0 by \a pexp. */
extern double frexp (double x, int *pexp);
/** The frexpl() function breaks a floating-point number into a normalized
    fraction and an integral power of 2.  It stores the integer in the \c
    int object pointed to by \a pexp.

    If \a x is a normal float point number, the frexpl() function
    returns the value \c v, such that \c v has a magnitude in the
    interval [1/2, 1) or zero, and \a x equals \c v times 2 raised to
    the power \a pexp. If \a x is zero, both parts of the result are
    zero. If \a x is not a finite number, the frexpl() returns \a x as
    is and stores 0 by \a pexp. */
extern long double frexpl (long double x, int *pexp);

/** The ldexpf() function multiplies a floating-point number by an integral
    power of 2. It returns the value of \a x times 2 raised to the power
    \a iexp. */
__ATTR_CONST__ extern float ldexpf (float x, int iexp);
/** The ldexp() function multiplies a floating-point number by an integral
    power of 2. It returns the value of \a x times 2 raised to the power
    \a iexp. */
__ATTR_CONST__ extern double ldexp (double x, int iexp);
/** The ldexpl() function multiplies a floating-point number by an integral
    power of 2. It returns the value of \a x times 2 raised to the power
    \a iexp. */
__ATTR_CONST__ extern long double ldexpl (long double x, int iexp);

/** The expf() function returns the exponential value of \a x. */
__ATTR_CONST__ extern float expf (float x);
/** The exp() function returns the exponential value of \a x. */
__ATTR_CONST__ extern double exp (double x);
/** The expl() function returns the exponential value of \a x. */
__ATTR_CONST__ extern long double expl (long double x);

/** The coshf() function returns the hyperbolic cosine of \a x. */
__ATTR_CONST__ extern float coshf (float x);
/** The cosh() function returns the hyperbolic cosine of \a x. */
__ATTR_CONST__ extern double cosh (double x);
/** The coshl() function returns the hyperbolic cosine of \a x. */
__ATTR_CONST__ extern long double coshl (long double x);

/** The sinhf() function returns the hyperbolic sine of \a x. */
__ATTR_CONST__ extern float sinhf (float x);
/** The sinh() function returns the hyperbolic sine of \a x. */
__ATTR_CONST__ extern double sinh (double x);
/** The sinhl() function returns the hyperbolic sine of \a x. */
__ATTR_CONST__ extern long double sinhl (long double x);

/** The tanhf() function returns the hyperbolic tangent of \a x. */
__ATTR_CONST__ extern float tanhf (float x);
/** The tanh() function returns the hyperbolic tangent of \a x. */
__ATTR_CONST__ extern double tanh (double x);
/** The tanhl() function returns the hyperbolic tangent of \a x. */
__ATTR_CONST__ extern long double tanhl (long double x);

/** The acosf() function computes the principal value of the arc cosine of
    \a x.  The returned value is in the range [0, pi] radians. A domain
    error occurs for arguments not in the range [&minus;1, +1]. */
__ATTR_CONST__ extern float acosf (float x);
/** The acos() function computes the principal value of the arc cosine of
    \a x.  The returned value is in the range [0, pi] radians or NaN. */
__ATTR_CONST__ extern double acos (double x);
/** The acosl() function computes the principal value of the arc cosine of
    \a x.  The returned value is in the range [0, pi] radians or NaN. */
__ATTR_CONST__ extern long double acosl (long double x);

/** The asinf() function computes the principal value of the arc sine of
    \a x.  The returned value is in the range [&minus;pi/2, pi/2] radians. A
    domain error occurs for arguments not in the range [&minus;1, +1]. */
__ATTR_CONST__ extern float asinf (float x);
/** The asin() function computes the principal value of the arc sine of
    \a x.  The returned value is in the range [&minus;pi/2, pi/2] radians or NaN. */
__ATTR_CONST__ extern double asin (double x);
/** The asinl() function computes the principal value of the arc sine of
    \a x.  The returned value is in the range [&minus;pi/2, pi/2] radians or NaN. */
__ATTR_CONST__ extern long double asinl (long double x);

/** The atanf() function computes the principal value of the arc tangent
    of \a x.  The returned value is in the range [&minus;pi/2, pi/2] radians. */
__ATTR_CONST__ extern float atanf (float x);
/** The atan() function computes the principal value of the arc tangent
    of \a x.  The returned value is in the range [&minus;pi/2, pi/2] radians. */
__ATTR_CONST__ extern double atan (double x);
/** The atanl() function computes the principal value of the arc tangent
    of \a x.  The returned value is in the range [&minus;pi/2, pi/2] radians. */
__ATTR_CONST__ extern long double atanl (long double x);

/** The atan2f() function computes the principal value of the arc tangent
    of <em>y / x</em>, using the signs of both arguments to determine
    the quadrant of the return value.  The returned value is in the range
    [&minus;pi, +pi] radians. */
__ATTR_CONST__ extern float atan2f (float y, float x);
/** The atan2() function computes the principal value of the arc tangent
    of <em>y / x</em>, using the signs of both arguments to determine
    the quadrant of the return value.  The returned value is in the range
    [&minus;pi, +pi] radians. */
__ATTR_CONST__ extern double atan2 (double y, double x);
/** The atan2l() function computes the principal value of the arc tangent
    of <em>y / x</em>, using the signs of both arguments to determine
    the quadrant of the return value.  The returned value is in the range
    [&minus;pi, +pi] radians. */
__ATTR_CONST__ extern long double atan2l (long double y, long double x);

/** The logf() function returns the natural logarithm of argument \a x. */
__ATTR_CONST__ extern float logf (float x);
/** The log() function returns the natural logarithm of argument \a x. */
__ATTR_CONST__ extern double log (double x);
/** The logl() function returns the natural logarithm of argument \a x. */
__ATTR_CONST__ extern long double logl (long double x);

/** The log10f() function returns the logarithm of argument \a x to base 10. */
__ATTR_CONST__ extern float log10f (float x);
/** The log10() function returns the logarithm of argument \a x to base 10. */
__ATTR_CONST__ extern double log10 (double x);
/** The log10l() function returns the logarithm of argument \a x to base 10. */
__ATTR_CONST__ extern long double log10l (long double x);

/** The function powf() returns the value of \a x to the exponent \a y.
    \n Notice that for integer exponents, there is the more efficient
    <code>float __builtin_powif(float x, int y)</code>. */
__ATTR_CONST__ extern float powf (float x, float y);
/** The function pow() returns the value of \a x to the exponent \a y.
    \n Notice that for integer exponents, there is the more efficient
    <code>double __builtin_powi(double x, int y)</code>. */
__ATTR_CONST__ extern double pow (double x, double y);
/** The function powl() returns the value of \a x to the exponent \a y.
    \n Notice that for integer exponents, there is the more efficient
    <code>long double __builtin_powil(long double x, int y)</code>. */
__ATTR_CONST__ extern long double powl (long double x, long double y);

/** The function isnanf() returns 1 if the argument \a x represents a
    "not-a-number" (NaN) object, otherwise 0. */
__ATTR_CONST__ extern int isnanf (float x);
/** The function isnan() returns 1 if the argument \a x represents a
    "not-a-number" (NaN) object, otherwise 0. */
__ATTR_CONST__ extern int isnan (double x);
/** The function isnanl() returns 1 if the argument \a x represents a
    "not-a-number" (NaN) object, otherwise 0. */
__ATTR_CONST__ extern int isnanl (long double x);

/** The function isinff() returns 1 if the argument \a x is positive
    infinity, &minus;1 if \a x is negative infinity, and 0 otherwise. */
__ATTR_CONST__ extern int isinff (float x);
/** The function isinf() returns 1 if the argument \a x is positive
    infinity, &minus;1 if \a x is negative infinity, and 0 otherwise. */
__ATTR_CONST__ extern int isinf (double x);
/** The function isinfl() returns 1 if the argument \a x is positive
    infinity, &minus;1 if \a x is negative infinity, and 0 otherwise. */
__ATTR_CONST__ extern int isinfl (long double x);

/** The isfinitef() function returns a nonzero value if \a __x is finite:
    not plus or minus infinity, and not NaN. */
__ATTR_CONST__ static __ATTR_ALWAYS_INLINE__ int isfinitef (float __x)
{
    unsigned char __exp;
    __asm__ (
        "mov    %0, %C1"     "\n\t"
        "lsl    %0"          "\n\t"
        "mov    %0, %D1"     "\n\t"
        "rol    %0"
        : "=&r" (__exp)
        : "r" (__x) );
    return __exp != 0xff;
}

/** The isfinite() function returns a nonzero value if \a __x is finite:
    not plus or minus infinity, and not NaN. */
#ifdef __DOXYGEN__
static __ATTR_ALWAYS_INLINE__ int isfinite (double __x);
#elif __SIZEOF_DOUBLE__ == __SIZEOF_FLOAT__
static __ATTR_ALWAYS_INLINE__ int isfinite (double __x)
{
    return isfinitef (__x);
}
#else
int isfinite (double __x);
#endif /* double = float */

/** The isfinite() function returns a nonzero value if \a __x is finite:
    not plus or minus infinity, and not NaN. */
#ifdef __DOXYGEN__
static __ATTR_ALWAYS_INLINE__ int isfinitel (long double __x);
#elif __SIZEOF_LONG_DOUBLE__ == __SIZEOF_FLOAT__
static __ATTR_ALWAYS_INLINE__ int isfinitel (long double __x)
{
    return isfinitef (__x);
}
#else
int isfinitel (long double __x);
#endif /* long double = float */

/** The copysignf() function returns \a __x but with the sign of \a __y.
    They work even if \a __x or \a __y are NaN or zero. */
__ATTR_CONST__ static __ATTR_ALWAYS_INLINE__ float copysignf (float __x, float __y)
{
    __asm__ (
        "bst    %D2, 7"  "\n\t"
        "bld    %D0, 7"
        : "=r" (__x)
        : "0" (__x), "r" (__y));
    return __x;
}

/** The copysign() function returns \a __x but with the sign of \a __y.
    They work even if \a __x or \a __y are NaN or zero. */
__ATTR_CONST__ static __ATTR_ALWAYS_INLINE__ double copysign (double __x, double __y)
{
    __asm__ (
        "bst    %r1+%2-1, 7" "\n\t"
        "bld    %r0+%2-1, 7"
        : "+r" (__x)
        : "r" (__y), "n" (__SIZEOF_DOUBLE__));
    return __x;
}

/** The copysignl() function returns \a __x but with the sign of \a __y.
    They work even if \a __x or \a __y are NaN or zero. */
__ATTR_CONST__ static __ATTR_ALWAYS_INLINE__ long double copysignl (long double __x, long double __y)
{
    __asm__ (
        "bst	%r1+%2-1, 7" "\n\t"
        "bld	%r0+%2-1, 7"
        : "+r" (__x)
        : "r" (__y), "n" (__SIZEOF_LONG_DOUBLE__));
    return __x;
}

/** The signbitf() function returns a nonzero value if the value of \a x
    has its sign bit set.  This is not the same as `\a x < 0.0',
    because IEEE 754 floating point allows zero to be signed. The
    comparison '&minus;0.0 < 0.0' is false, but `signbit (&minus;0.0)' will return a
    nonzero value. */
__ATTR_CONST__ extern int signbitf (float x);
/** The signbit() function returns a nonzero value if the value of \a x
    has its sign bit set.  This is not the same as `\a x < 0.0',
    because IEEE 754 floating point allows zero to be signed. The
    comparison '&minus;0.0 < 0.0' is false, but `signbit (&minus;0.0)' will return a
    nonzero value. */
__ATTR_CONST__ extern int signbit (double x);
/** The signbitl() function returns a nonzero value if the value of \a x
    has its sign bit set.  This is not the same as `\a x < 0.0',
    because IEEE 754 floating point allows zero to be signed. The
    comparison '&minus;0.0 < 0.0' is false, but `signbit (&minus;0.0)' will return a
    nonzero value. */
__ATTR_CONST__ extern int signbitl (long double x);

/** The fdimf() function returns <em>max(x &minus; y, 0)</em>. If \a x or
    \a y or both are NaN, NaN is returned. */
__ATTR_CONST__ extern float fdimf (float x, float y);
/** The fdim() function returns <em>max(x &minus; y, 0)</em>. If \a x or
    \a y or both are NaN, NaN is returned. */
__ATTR_CONST__ extern double fdim (double x, double y);
/** The fdiml() function returns <em>max(x &minus; y, 0)</em>. If \a x or
    \a y or both are NaN, NaN is returned. */
__ATTR_CONST__ extern long double fdiml (long double x, long double y);

/** The fmaf() function performs floating-point multiply-add. This is the
    operation <em>(x * y) + z</em>, but the intermediate result is
    not rounded to the destination type.  This can sometimes improve the
    precision of a calculation. */
__ATTR_CONST__ extern float fmaf (float x, float y, float z);
/** The fma() function performs floating-point multiply-add. This is the
    operation <em>(x * y) + z</em>, but the intermediate result is
    not rounded to the destination type.  This can sometimes improve the
    precision of a calculation. */
__ATTR_CONST__ extern double fma (double x, double y, double z);
/** The fmal() function performs floating-point multiply-add. This is the
    operation <em>(x * y) + z</em>, but the intermediate result is
    not rounded to the destination type.  This can sometimes improve the
    precision of a calculation. */
__ATTR_CONST__ extern long double fmal (long double x, long double y, long double z);

/** The fmaxf() function returns the greater of the two values \a x and
    \a y. If an argument is NaN, the other argument is returned. If
    both arguments are NaN, NaN is returned. */
__ATTR_CONST__ extern float fmaxf (float x, float y);
/** The fmax() function returns the greater of the two values \a x and
    \a y. If an argument is NaN, the other argument is returned. If
    both arguments are NaN, NaN is returned. */
__ATTR_CONST__ extern double fmax (double x, double y);
/** The fmaxl() function returns the greater of the two values \a x and
    \a y. If an argument is NaN, the other argument is returned. If
    both arguments are NaN, NaN is returned. */
__ATTR_CONST__ extern long double fmaxl (long double x, long double y);

/** The fminf() function returns the lesser of the two values \a x and
    \a y. If an argument is NaN, the other argument is returned. If
    both arguments are NaN, NaN is returned. */
__ATTR_CONST__ extern float fminf (float x, float y);
/** The fmin() function returns the lesser of the two values \a x and
    \a y. If an argument is NaN, the other argument is returned. If
    both arguments are NaN, NaN is returned. */
__ATTR_CONST__ extern double fmin (double x, double y);
/** The fminl() function returns the lesser of the two values \a x and
    \a y. If an argument is NaN, the other argument is returned. If
    both arguments are NaN, NaN is returned. */
__ATTR_CONST__ extern long double fminl (long double x, long double y);

/** The truncf() function rounds \a x to the nearest integer not larger
    in absolute value. */
__ATTR_CONST__ extern float truncf (float x);
/** The trunc() function rounds \a x to the nearest integer not larger
    in absolute value. */
__ATTR_CONST__ extern double trunc (double x);
/** The truncl() function rounds \a x to the nearest integer not larger
    in absolute value. */
__ATTR_CONST__ extern long double truncl (long double x);

/** The roundf() function rounds \a x to the nearest integer, but rounds
    halfway cases away from zero (instead of to the nearest even integer).
    Overflow is impossible.

    \return The rounded value. If \a x is an integral or infinite, \a
    x itself is returned. If \a x is \c NaN, then \c NaN is returned. */
__ATTR_CONST__ extern float roundf (float x);
/** The round() function rounds \a x to the nearest integer, but rounds
    halfway cases away from zero (instead of to the nearest even integer).
    Overflow is impossible.

    \return The rounded value. If \a x is an integral or infinite, \a
    x itself is returned. If \a x is \c NaN, then \c NaN is returned. */
__ATTR_CONST__ extern double round (double x);
/** The roundl() function rounds \a x to the nearest integer, but rounds
    halfway cases away from zero (instead of to the nearest even integer).
    Overflow is impossible.

    \return The rounded value. If \a x is an integral or infinite, \a
    x itself is returned. If \a x is \c NaN, then \c NaN is returned. */
__ATTR_CONST__ extern long double roundl (long double x);

/** The lroundf() function rounds \a x to the nearest integer, but rounds
    halfway cases away from zero (instead of to the nearest even integer).
    This function is similar to round() function, but it differs in type of
    return value and in that an overflow is possible.

    \return The rounded long integer value. If \a x is not a finite number
    or an overflow was, this realization returns the \c LONG_MIN value
    (0x80000000). */
__ATTR_CONST__ extern long lroundf (float x);
/** The lround() function rounds \a x to the nearest integer, but rounds
    halfway cases away from zero (instead of to the nearest even integer).
    This function is similar to round() function, but it differs in type of
    return value and in that an overflow is possible.

    \return The rounded long integer value. If \a x is not a finite number
    or an overflow was, this realization returns the \c LONG_MIN value
    (0x80000000). */
__ATTR_CONST__ extern long lround (double x);
/** The lroundl() function rounds \a x to the nearest integer, but rounds
    halfway cases away from zero (instead of to the nearest even integer).
    This function is similar to round() function, but it differs in type of
    return value and in that an overflow is possible.

    \return The rounded long integer value. If \a x is not a finite number
    or an overflow was, this realization returns the \c LONG_MIN value
    (0x80000000). */
__ATTR_CONST__ extern long lroundl (long double x);

/** The lrintf() function rounds \a x to the nearest integer, rounding the
    halfway cases to the even integer direction. (That is both 1.5 and 2.5
    values are rounded to 2). This function is similar to rintf() function,
    but it differs in type of return value and in that an overflow is
    possible.

    \return The rounded long integer value. If \a x is not a finite
    number or an overflow was, this realization returns the \c LONG_MIN
    value (0x80000000). */
__ATTR_CONST__ extern long lrintf (float x);
/** The lrint() function rounds \a x to the nearest integer, rounding the
    halfway cases to the even integer direction. (That is both 1.5 and 2.5
    values are rounded to 2). This function is similar to rint() function,
    but it differs in type of return value and in that an overflow is
    possible.

    \return The rounded long integer value. If \a x is not a finite
    number or an overflow was, this realization returns the \c LONG_MIN
    value (0x80000000). */
__ATTR_CONST__ extern long lrint (double x);
/** The lrintl() function rounds \a x to the nearest integer, rounding the
    halfway cases to the even integer direction. (That is both 1.5 and 2.5
    values are rounded to 2). This function is similar to rintl() function,
    but it differs in type of return value and in that an overflow is
    possible.

    \return The rounded long integer value. If \a x is not a finite
    number or an overflow was, this realization returns the \c LONG_MIN
    value (0x80000000). */
__ATTR_CONST__ extern long lrintl (long double x);

/**@}*/

/**@{*/
/**
   \name Non-Standard Math Functions
*/

/** \ingroup avr_math
    The function squaref() returns <em>x * x</em>.
    \note This function does not belong to the C standard definition. */
__ATTR_CONST__ extern float squaref (float x);

/** The function square() returns <em>x * x</em>.
    \note This function does not belong to the C standard definition. */

#if defined(__DOXYGEN__) || __SIZEOF_DOUBLE__ == __SIZEOF_FLOAT__
__ATTR_CONST__ extern double square (double x);
#elif defined(__WITH_LIBF7_MATH__)
__ATTR_CONST__ extern double square (double x) __asm("__f7_square");
#endif

/** The function squarel() returns <em>x * x</em>.
    \note This function does not belong to the C standard definition. */
#if defined(__DOXYGEN__) || __SIZEOF_LONG_DOUBLE__ == __SIZEOF_FLOAT__
__ATTR_CONST__ extern long double squarel (long double x);
#elif defined(__WITH_LIBF7_MATH__)
__ATTR_CONST__ extern long double squarel (long double x) __asm("__f7_square");
#endif

/**@}*/

#ifdef __cplusplus
}
#endif

#endif /* !__MATH_H */