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
stdfix-avrlibc.h
Go to the documentation of this file.
1/* Copyright (c) 2013 Joerg Wunsch
2 All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
6
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in
12 the documentation and/or other materials provided with the
13 distribution.
14
15 * Neither the name of the copyright holders nor the names of
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 POSSIBILITY OF SUCH DAMAGE. */
30
31#ifndef _STDFIX_AVRLIBC_H
32#define _STDFIX_AVRLIBC_H
33
34/*
35 * AVR-LibC addendum file for Embedded C Fixed-Point support
36 *
37 * See: ISO/IEC TR 18037
38 * http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf
39 */
40
41#ifndef _AVRGCC_STDFIX_H /* Defined in stdfix.h from avr-gcc */
42#warning please include <stdfix.h> directly rather than <stdfix-avrlibc.h>
43#endif /* _AVRGCC_STDFIX_H */
44
45#include <bits/attribs.h>
46
47/** \file */
48/** \defgroup avr_stdfix <stdfix.h>: ISO/IEC TR 18037 Fixed-Point Arithmetic
49 \code #include <stdfix.h> \endcode
50
51As an extension, GNU C supports fixed-point types as defined in the
52N1169 draft of ISO/IEC DTR 18037.
53
54\since <a href="https://gcc.gnu.org/gcc-4.8/changes.html#avr"
55 >avr-gcc v4.8</a>
56
57Two groups of fixed-point data types are added:
58- The <em>fract types</em> and the <em>accum types</em>.
59 The data value of a \e fract type has no integral part,
60 hence values of a \e fract type are between &minus;1.0 and +1.0.
61- The value range of an \e accum type depends on the number of integral bits
62 in the data type.
63
64<table>
65<caption>Fixed-Point Type Layout</caption>
66<tr><th>Const Suffix <th>Type <th>Size <th>Q-Format
67<tr><td align="right"><tt>hr</tt> <td align="right"><tt>short fract</tt> <td>1<td>s.7
68<tr><td align="right"><tt>r</tt> <td align="right"><tt>fract</tt> <td>2<td>s.15
69<tr><td align="right"><tt>lr</tt> <td align="right"><tt>long fract</tt> <td>4<td>s.31
70<tr><td align="right"><tt>llr</tt> <td align="right"><tt>long long fract</tt> <td>8<td>s.63
71<tr><td align="right"><tt>hk</tt> <td align="right"><tt>short accum</tt> <td>2<td>s8.7
72<tr><td align="right"><tt>k</tt> <td align="right"><tt>accum</tt> <td>4<td>s16.15
73<tr><td align="right"><tt>lk</tt> <td align="right"><tt>long accum</tt> <td>8<td>s32.31
74<tr><td align="right"><tt>llk</tt> <td align="right"><tt>long long accum</tt> <td>8<td>s16.47
75<tr><td align="right"><tt>uhr</tt> <td align="right"><tt>unsigned short fract</tt> <td>1<td>0.8
76<tr><td align="right"><tt>ur</tt> <td align="right"><tt>unsigned fract</tt> <td>2<td>0.16
77<tr><td align="right"><tt>ulr</tt> <td align="right"><tt>unsigned long fract</tt> <td>4<td>0.32
78<tr><td align="right"><tt>ullr</tt><td align="right"><tt>unsigned long long fract</tt><td>8<td>0.64
79<tr><td align="right"><tt>uhk</tt> <td align="right"><tt>unsigned short accum</tt> <td>2<td>8.8
80<tr><td align="right"><tt>uk</tt> <td align="right"><tt>unsigned accum</tt> <td>4<td>16.16
81<tr><td align="right"><tt>ulk</tt> <td align="right"><tt>unsigned long accum</tt> <td>8<td>32.32
82<tr><td align="right"><tt>ullk</tt><td align="right"><tt>unsigned long long accum</tt> <td>8<td>16.48
83</table>
84\remark
85 - Upper case constant suffixes are also supported.
86 - The \c long \c long fixed-point types are avr-gcc extensions.
87
88See also some \ref bench_fxlib "benchmarks".
89*/
90
91
92/* Room for AVR-LibC specific extensions */
93
94/* 7.18a.6.1 The fixed-point arithmetic operation support functions */
95
96#ifdef __cplusplus
97extern "C" {
98#endif
99
100/** \ingroup avr_stdfix
101 Include all significant digits in the result of a
102 fixed-point to decimal ASCII conversion.
103 The result has no trailing zeros.
104
105 To be used in the \a mode parameter of such a conversion.
106 For details and examples, see uktoa().
107 \since AVR-LibC v2.3 */
108#define FXTOA_ALL 0x1f
109
110/** \ingroup avr_stdfix
111 A flag to select rounding to nearest in a fixed-point to
112 decimal ASCII conversion. Rounding mode is the default,
113 i.e. FXTOA_ROUND can be omitted.
114
115 To be used in the \a mode parameter of such a conversion.
116 For details and examples, see uktoa().
117 \since AVR-LibC v2.3 */
118#define FXTOA_ROUND 0x00
119
120/** \ingroup avr_stdfix
121 A flag to select truncation (rounding to zero) in a fixed-point to
122 decimal ASCII conversion.
123
124 To be used in the \a mode parameter of such a conversion.
125 For details and examples, see uktoa().
126 \since AVR-LibC v2.3 */
127#define FXTOA_TRUNC 0x80
128
129/** \ingroup avr_stdfix
130 A flag to select that the result of a fixed-point to
131 decimal ASCII conversion has no trailing zeros.
132
133 To be used in the \a mode parameter of such a conversion.
134 For details and examples, see uktoa().
135 \since AVR-LibC v2.3 */
136#define FXTOA_NTZ 0x40
137
138/** \ingroup avr_stdfix
139 The fixed-point to decimal ASCII conversion routines use a
140 dot (<tt>.</tt>) for the decimal point. This is the default, i.e.
141 FXTOA_DOT can be omitted.
142
143 For details, and examples, see uktoa().
144 \since AVR-LibC v2.3 */
145#define FXTOA_DOT 0x00
146
147/** \ingroup avr_stdfix
148 The fixed-point to decimal ASCII conversion routines use a
149 comma (<tt>,</tt>) for the decimal point.
150
151 For details and examples, see uktoa().
152 \since AVR-LibC v2.3 */
153#define FXTOA_COMMA 0x20
154
155
156#ifdef __DOXYGEN__
157
158/** \name ASCII Conversions (not in ISO/IEC TR18037) */
159
160/** \ingroup avr_stdfix
161 Convert fixed-point value \p x to a decimal ASCII representation.
162 The result is written to \p buf, and the user is responsible for
163 providing enough memory in \p buf. Returns \p buf.
164
165 For the meaning of \p mode, and for the (maximal) number of
166 character written by this function, see uktoa().
167 \since AVR-LibC v2.3 */
168char* hktoa (short accum x, char *buf, unsigned char mode);
169
170/** \ingroup avr_stdfix
171 Convert fixed-point value \p x to a decimal ASCII representation.
172 The result is written to \p buf, and the user is responsible for
173 providing enough memory in \p buf. Returns \p buf.
174
175 For the meaning of \p mode, and for the (maximal) number of
176 character written by this function, see uktoa().
177 \since AVR-LibC v2.3 */
178char* hrtoa (short fract x, char *buf, unsigned char mode);
179
180/** \ingroup avr_stdfix
181 Convert fixed-point value \p x to a decimal ASCII representation.
182 The result is written to \p buf, and the user is responsible for
183 providing enough memory in \p buf. Returns \p buf.
184
185 For the meaning of \p mode, and for the (maximal) number of
186 character written by this function, see uktoa().
187 \since AVR-LibC v2.3 */
188char* ktoa (accum x, char *buf, unsigned char mode);
189
190/** \ingroup avr_stdfix
191 Convert fixed-point value \p x to a decimal ASCII representation.
192 The result is written to \p buf, and the user is responsible for
193 providing enough memory in \p buf. Returns \p buf.
194
195 For the meaning of \p mode, and for the (maximal) number of
196 character written by this function, see uktoa().
197 \since AVR-LibC v2.3 */
198char* rtoa (fract x, char *buf, unsigned char mode);
199
200/** \ingroup avr_stdfix
201 Convert fixed-point value \p x to a decimal ASCII representation.
202 The result is written to \p buf, and the user is responsible for
203 providing enough memory in \p buf. Returns \p buf.
204
205 For the meaning of \p mode, and for the (maximal) number of
206 character written by this function, see uktoa().
207 \since AVR-LibC v2.3 */
208char* uhktoa (unsigned short accum x, char *buf, unsigned char mode);
209
210/** \ingroup avr_stdfix
211 Convert fixed-point value \p x to a decimal ASCII representation.
212 The result is written to \p buf, and the user is responsible for
213 providing enough memory in \p buf. Returns \p buf.
214
215 For the meaning of \p mode, and for the (maximal) number of
216 character written by this function, see uktoa().
217 \since AVR-LibC v2.3 */
218char* uhrtoa (unsigned short fract x, char *buf, unsigned char mode);
219
220/** \ingroup avr_stdfix
221 Convert fixed-point value \p x to a decimal ASCII representation.
222 The result is written to \p buf, and the user is responsible for
223 providing enough memory in \p buf. Returns \p buf.
224
225 The format of the output is controlled by the \a mode parameter.
226 It is composed from the format flags below together with \a Digs,
227 the number of fractional digits.
228 The \p mode is the ORed result from \a Digs and a combination of
229 #FXTOA_ALL, #FXTOA_ROUND or #FXTOA_TRUNC, #FXTOA_DOT or #FXTOA_COMMA,
230 and #FXTOA_NTZ, like in:
231 \code
232 uktoa (x, buf, FXTOA_ROUND | FXTOA_NTZ | Digs);
233 \endcode
234
235 - Supported values for \a Digs are in the range 0...30.
236
237<dl>
238 <dt>#FXTOA_ALL
239 <dd>Include all significant digits. \a Digs will be ignored.
240
241 <dt>#FXTOA_ROUND
242 <dd>Round to nearest for \a Digs fractional digits.
243 Rounding for \a Digs &ge; 5 has no effect, i.e. for such \a Digs values
244 the rounded result will be the same like the truncated result.
245 Rounding mode is the default, i.e. FXTOA_ROUND can be omitted.
246
247 <dt>#FXTOA_TRUNC
248 <dd>Like FXTOA_ALL, but truncate the result (round to zero)
249 after \a Digs fractional digits.
250
251 <dt>#FXTOA_NTZ
252 <dd>
253 &bull;&nbsp;With FXTOA_NTZ the result has
254 <b>n</b>o <b>t</b>railing <b>z</b>eros.
255 When the result represents an integral value,
256 then no decimal point and no fractional digits are present.<br>
257 &bull;&nbsp;Without FXTOA_NTZ and with FXTOA_ROUND or FXTOA_TRUNC,
258 the result has the specified number of fractional digits.<br>
259 &bull;&nbsp;FXTOA_NTZ has no effect with FXTOA_ALL.<br>
260 &bull;&nbsp;FXTOA_NTZ has no effect on the required buffer size.
261 <dt>#FXTOA_DOT
262 <dd>The decimal point is a dot (\c .). This is the default, i.e. FXTOA_DOT
263 can be omitted.
264
265 <dt>#FXTOA_COMMA
266 <dd>The decimal point is a comma (\c ,).
267</dl>
268
269<table>
270<caption>Examples</caption>
271<tr>
272 <th>Value
273 <th>Mode
274 <th>Result
275</tr>
276<tr><td>1.8uk<td><tt>0</tt><td><tt>"2"</tt></tr>
277<tr><td>1.8uk<td><tt>1</tt><td><tt>"1.8"</tt></tr>
278<tr><td>1.8uk<td><tt>2</tt><td><tt>"1.80"</tt></tr>
279<tr><td>1.8uk<td><tt>3</tt><td><tt>"1.800"</tt></tr>
280<tr><td>1.8uk<td><tt>FXTOA_NTZ | 0</tt><td><tt>"2"</tt></tr>
281<tr><td>1.8uk<td><tt>FXTOA_NTZ | 1</tt><td><tt>"1.8"</tt></tr>
282<tr><td>1.8uk<td><tt>FXTOA_NTZ | 2</tt><td><tt>"1.8"</tt></tr>
283<tr><td>1.8uk<td><tt>FXTOA_NTZ | 3</tt><td><tt>"1.8"</tt></tr>
284<tr><td>1.8uk<td><tt>FXTOA_TRUNC | FXTOA_COMMA | 0</tt><td><tt>"1"</tt></tr>
285<tr><td>1.8uk<td><tt>FXTOA_TRUNC | FXTOA_COMMA | 1</tt><td><tt>"1,7"</tt></tr>
286<tr><td>1.8uk<td><tt>FXTOA_TRUNC | FXTOA_COMMA | 2</tt><td><tt>"1,79"</tt></tr>
287<tr><td>1.8uk<td><tt>FXTOA_TRUNC | FXTOA_COMMA | 3</tt><td><tt>"1,799"</tt></tr>
288<tr><td>1.8uk<td><tt>FXTOA_ALL</tt> <td><tt>"1.79998779296875"</tt></tr>
289</table>
290
291The following table helps with providing enough memory in \a buf.
292
293Notice that the required size of \a buf is independent of #FXTOA_NTZ.
294This is the case since with #FXTOA_NTZ the required buffer size may
295be larger that the size of the returned string.
296
297<table>
298 <caption>Maximum Number of Bytes written to buf</caption>
299 <tr>
300 <th>Type
301 <th>Function
302 <th>FXTOA_ALL
303 <th>All other Modes
304 <th colspan="2">Exact Maximal Value
305 </tr>
306 <tr>
307 <td align="right"><tt>unsigned accum</tt>
308 <td align="right">#uktoa
309 <td align="center">23
310 <td align="center">7 + \a Digs
311 <td align="center">2<sup>16</sup>&minus;2<sup>&minus;16</sup>
312 <td>65535.9999847412109375
313 <tr>
314 <td align="right"><tt>accum</tt>
315 <td align="right">#ktoa
316 <td align="center">23
317 <td align="center">8 + \a Digs
318 <td align="center">2<sup>16</sup>&minus;2<sup>&minus;15</sup>
319 <td>65535.999969482421875
320 <tr>
321 <td align="right"><tt>unsigned short accum</tt>
322 <td align="right">#uhktoa
323 <td align="center">13
324 <td align="center">5 + \a Digs
325 <td align="center">2<sup>8</sup>&minus;2<sup>&minus;8</sup>
326 <td>255.99609375
327 <tr>
328 <td align="right"><tt>short accum</tt>
329 <td align="right">#hktoa
330 <td align="center">13
331 <td align="center">6 + \a Digs
332 <td align="center">2<sup>8</sup>&minus;2<sup>&minus;7</sup>
333 <td>255.9921875
334 <tr>
335 <td align="right"><tt>unsigned fract</tt>
336 <td align="right">#urtoa
337 <td align="center">19
338 <td align="center">3 + \a Digs
339 <td align="center">1&minus;2<sup>&minus;16</sup>
340 <td>0.9999847412109375
341 <tr>
342 <td align="right"><tt>fract</tt>
343 <td align="right">#rtoa
344 <td align="center">19
345 <td align="center">4 + \a Digs
346 <td align="center">1&minus;2<sup>&minus;15</sup>
347 <td>0.999969482421875
348 <tr>
349 <td align="right"><tt>unsigned short fract</tt>
350 <td align="right">#uhrtoa
351 <td align="center">11
352 <td align="center">3 + \a Digs
353 <td align="center">1&minus;2<sup>&minus;8</sup>
354 <td>0.99609375
355 <tr>
356 <td align="right"><tt>short fract</tt>
357 <td align="right">#hrtoa
358 <td align="center">11
359 <td align="center">4 + \a Digs
360 <td align="center">1&minus;2<sup>&minus;7</sup>
361 <td>0.9921875
362 </tr>
363</table>
364
365 \since AVR-LibC v2.3 */
366char* uktoa (unsigned accum x, char *buf, unsigned char mode);
367
368/** \ingroup avr_stdfix
369 Convert fixed-point value \p x to a decimal ASCII representation.
370 The result is written to \p buf, and the user is responsible for
371 providing enough memory in \p buf. Returns \p buf.
372
373 For the meaning of \p mode, and for the (maximal) number of
374 character written by this function, see uktoa().
375 \since AVR-LibC v2.3 */
376char* urtoa (unsigned fract x, char *buf, unsigned char mode);
377
378
379/** \name Absolute Value */
380
381/** \ingroup avr_stdfix
382 Computes the absolute value of \p val. When the result does not
383 fit into the range of the return type, the result is saturated. */
384short fract abshr (short fract val);
385
386/** \ingroup avr_stdfix
387 Computes the absolute value of \p val. When the result does not
388 fit into the range of the return type, the result is saturated. */
389fract absr (fract val);
390
391/** \ingroup avr_stdfix
392 Computes the absolute value of \p val. When the result does not
393 fit into the range of the return type, the result is saturated. */
394long fract abslr (long fract val);
395
396/** \ingroup avr_stdfix
397 Computes the absolute value of \p val. When the result does not
398 fit into the range of the return type, the result is saturated. */
399long long fract absllr (long long fract val);
400
401/** \ingroup avr_stdfix
402 Computes the absolute value of \p val. When the result does not
403 fit into the range of the return type, the result is saturated. */
404short accum abshk (short accum val);
405
406/** \ingroup avr_stdfix
407 Computes the absolute value of \p val. When the result does not
408 fit into the range of the return type, the result is saturated. */
409accum absk (accum val);
410
411/** \ingroup avr_stdfix
412 Computes the absolute value of \p val. When the result does not
413 fit into the range of the return type, the result is saturated. */
414long accum abslk (long accum val);
415
416/** \ingroup avr_stdfix
417 Computes the absolute value of \p val. When the result does not
418 fit into the range of the return type, the result is saturated. */
419long long accum absllk (long long accum val);
420
421
422/** \name Bit-Conversions to Integer */
423
424/** \ingroup avr_stdfix
425 Return an integer value of the same size and signedness,
426 and with the same bit representation like \p val. */
427signed char bitshr (short fract val);
428
429/** \ingroup avr_stdfix
430 Return an integer value of the same size and signedness,
431 and with the same bit representation like \p val. */
432unsigned char bitsuhr (unsigned short fract val);
433
434/** \ingroup avr_stdfix
435 Return an integer value of the same size and signedness,
436 and with the same bit representation like \p val. */
437int bitsr (fract val);
438
439/** \ingroup avr_stdfix
440 Return an integer value of the same size and signedness,
441 and with the same bit representation like \p val. */
442unsigned int bitsur (unsigned fract val);
443
444/** \ingroup avr_stdfix
445 Return an integer value of the same size and signedness,
446 and with the same bit representation like \p val. */
447long bitslr (long fract val);
448
449/** \ingroup avr_stdfix
450 Return an integer value of the same size and signedness,
451 and with the same bit representation like \p val. */
452unsigned long bitsulr (unsigned long fract val);
453
454/** \ingroup avr_stdfix
455 Return an integer value of the same size and signedness,
456 and with the same bit representation like \p val. */
457long long bitsllr (long long fract val);
458
459/** \ingroup avr_stdfix
460 Return an integer value of the same size and signedness,
461 and with the same bit representation like \p val. */
462unsigned long long bitsullr (unsigned long long fract val);
463
464/** \ingroup avr_stdfix
465 Return an integer value of the same size and signedness,
466 and with the same bit representation like \p val. */
467int bitshk (short accum val);
468
469/** \ingroup avr_stdfix
470 Return an integer value of the same size and signedness,
471 and with the same bit representation like \p val. */
472unsigned int bitsuhk (unsigned short accum val);
473
474/** \ingroup avr_stdfix
475 Return an integer value of the same size and signedness,
476 and with the same bit representation like \p val. */
477long bitsk (accum val);
478
479/** \ingroup avr_stdfix
480 Return an integer value of the same size and signedness,
481 and with the same bit representation like \p val. */
482unsigned long bitsuk (unsigned accum val);
483
484/** \ingroup avr_stdfix
485 Return an integer value of the same size and signedness,
486 and with the same bit representation like \p val. */
487long long bitslk (long accum val);
488
489/** \ingroup avr_stdfix
490 Return an integer value of the same size and signedness,
491 and with the same bit representation like \p val. */
492unsigned long long bitsulk (unsigned long accum val);
493
494/** \ingroup avr_stdfix
495 Return an integer value of the same size and signedness,
496 and with the same bit representation like \p val. */
497long long bitsllk (long long accum val);
498
499/** \ingroup avr_stdfix
500 Return an integer value of the same size and signedness,
501 and with the same bit representation like \p val. */
502unsigned long long bitsullk (unsigned long long accum val);
503
504
505/** \name Bit-Conversions to Fixed-Point */
506
507/** \ingroup avr_stdfix
508 Return a fixed-point value of the same size and signedness,
509 and with the same bit representation like \p val. */
510short fract hrbits (signed char val);
511
512/** \ingroup avr_stdfix
513 Return a fixed-point value of the same size and signedness,
514 and with the same bit representation like \p val. */
515unsigned short fract uhrbits (unsigned char val);
516
517/** \ingroup avr_stdfix
518 Return a fixed-point value of the same size and signedness,
519 and with the same bit representation like \p val. */
520fract rbits (int val);
521
522/** \ingroup avr_stdfix
523 Return a fixed-point value of the same size and signedness,
524 and with the same bit representation like \p val. */
525unsigned fract urbits (unsigned int val);
526
527/** \ingroup avr_stdfix
528 Return a fixed-point value of the same size and signedness,
529 and with the same bit representation like \p val. */
530long fract lrbits (long val);
531
532/** \ingroup avr_stdfix
533 Return a fixed-point value of the same size and signedness,
534 and with the same bit representation like \p val. */
535unsigned long fract ulrbits (unsigned long val);
536
537/** \ingroup avr_stdfix
538 Return a fixed-point value of the same size and signedness,
539 and with the same bit representation like \p val. */
540long long fract llrbits (long long val);
541
542/** \ingroup avr_stdfix
543 Return a fixed-point value of the same size and signedness,
544 and with the same bit representation like \p val. */
545unsigned long long fract ullrbits (unsigned long long val);
546
547/** \ingroup avr_stdfix
548 Return a fixed-point value of the same size and signedness,
549 and with the same bit representation like \p val. */
550short accum hkbits (int val);
551
552/** \ingroup avr_stdfix
553 Return a fixed-point value of the same size and signedness,
554 and with the same bit representation like \p val. */
555unsigned short accum uhkbits (unsigned int val);
556
557/** \ingroup avr_stdfix
558 Return a fixed-point value of the same size and signedness,
559 and with the same bit representation like \p val. */
560accum kbits (long val);
561
562/** \ingroup avr_stdfix
563 Return a fixed-point value of the same size and signedness,
564 and with the same bit representation like \p val. */
565unsigned accum ukbits (unsigned long val);
566
567/** \ingroup avr_stdfix
568 Return a fixed-point value of the same size and signedness,
569 and with the same bit representation like \p val. */
570long accum lkbits (long long val);
571
572/** \ingroup avr_stdfix
573 Return a fixed-point value of the same size and signedness,
574 and with the same bit representation like \p val. */
575unsigned long accum ulkbits (unsigned long long val);
576
577/** \ingroup avr_stdfix
578 Return a fixed-point value of the same size and signedness,
579 and with the same bit representation like \p val. */
580long long accum llkbits (long long val);
581
582/** \ingroup avr_stdfix
583 Return a fixed-point value of the same size and signedness,
584 and with the same bit representation like \p val. */
585unsigned long long accum ullkbits (unsigned long long val);
586
587/** \name Count Left-Shift */
588
589/** \ingroup avr_stdfix
590 - If \p val is non-zero, the return value is the largest integer
591 \c k for which the expression <tt>val &lt;&lt; k</tt> does not overflow.
592 - If \p val is zero, an integer value is returned that is at least
593 as large as <tt>N - 1</tt>, where <tt>N</tt> is the total number
594 of bits of the type of the argument. */
595int countlshr (short fract val);
596
597/** \ingroup avr_stdfix
598 - If \p val is non-zero, the return value is the largest integer
599 \c k for which the expression <tt>val &lt;&lt; k</tt> does not overflow.
600 - If \p val is zero, an integer value is returned that is at least
601 as large as <tt>N - 1</tt>, where <tt>N</tt> is the total number
602 of bits of the type of the argument. */
603int countlsuhr (unsigned short fract val);
604
605/** \ingroup avr_stdfix
606 - If \p val is non-zero, the return value is the largest integer
607 \c k for which the expression <tt>val &lt;&lt; k</tt> does not overflow.
608 - If \p val is zero, an integer value is returned that is at least
609 as large as <tt>N - 1</tt>, where <tt>N</tt> is the total number
610 of bits of the type of the argument. */
611int countlsr (fract val);
612
613/** \ingroup avr_stdfix
614 - If \p val is non-zero, the return value is the largest integer
615 \c k for which the expression <tt>val &lt;&lt; k</tt> does not overflow.
616 - If \p val is zero, an integer value is returned that is at least
617 as large as <tt>N - 1</tt>, where <tt>N</tt> is the total number
618 of bits of the type of the argument. */
619int countlsur (unsigned fract val);
620
621/** \ingroup avr_stdfix
622 - If \p val is non-zero, the return value is the largest integer
623 \c k for which the expression <tt>val &lt;&lt; k</tt> does not overflow.
624 - If \p val is zero, an integer value is returned that is at least
625 as large as <tt>N - 1</tt>, where <tt>N</tt> is the total number
626 of bits of the type of the argument. */
627int countlslr (long fract val);
628
629/** \ingroup avr_stdfix
630 - If \p val is non-zero, the return value is the largest integer
631 \c k for which the expression <tt>val &lt;&lt; k</tt> does not overflow.
632 - If \p val is zero, an integer value is returned that is at least
633 as large as <tt>N - 1</tt>, where <tt>N</tt> is the total number
634 of bits of the type of the argument. */
635int countlsulr (unsigned long fract val);
636
637/** \ingroup avr_stdfix
638 - If \p val is non-zero, the return value is the largest integer
639 \c k for which the expression <tt>val &lt;&lt; k</tt> does not overflow.
640 - If \p val is zero, an integer value is returned that is at least
641 as large as <tt>N - 1</tt>, where <tt>N</tt> is the total number
642 of bits of the type of the argument. */
643int countlsllr (long long fract val);
644
645/** \ingroup avr_stdfix
646 - If \p val is non-zero, the return value is the largest integer
647 \c k for which the expression <tt>val &lt;&lt; k</tt> does not overflow.
648 - If \p val is zero, an integer value is returned that is at least
649 as large as <tt>N - 1</tt>, where <tt>N</tt> is the total number
650 of bits of the type of the argument. */
651int countlsullr (unsigned long long fract val);
652
653/** \ingroup avr_stdfix
654 - If \p val is non-zero, the return value is the largest integer
655 \c k for which the expression <tt>val &lt;&lt; k</tt> does not overflow.
656 - If \p val is zero, an integer value is returned that is at least
657 as large as <tt>N - 1</tt>, where <tt>N</tt> is the total number
658 of bits of the type of the argument. */
659int countlshk (short accum val);
660
661/** \ingroup avr_stdfix
662 - If \p val is non-zero, the return value is the largest integer
663 \c k for which the expression <tt>val &lt;&lt; k</tt> does not overflow.
664 - If \p val is zero, an integer value is returned that is at least
665 as large as <tt>N - 1</tt>, where <tt>N</tt> is the total number
666 of bits of the type of the argument. */
667int countlsuhk (unsigned short accum val);
668
669/** \ingroup avr_stdfix
670 - If \p val is non-zero, the return value is the largest integer
671 \c k for which the expression <tt>val &lt;&lt; k</tt> does not overflow.
672 - If \p val is zero, an integer value is returned that is at least
673 as large as <tt>N - 1</tt>, where <tt>N</tt> is the total number
674 of bits of the type of the argument. */
675int countlsk (accum val);
676
677/** \ingroup avr_stdfix
678 - If \p val is non-zero, the return value is the largest integer
679 \c k for which the expression <tt>val &lt;&lt; k</tt> does not overflow.
680 - If \p val is zero, an integer value is returned that is at least
681 as large as <tt>N - 1</tt>, where <tt>N</tt> is the total number
682 of bits of the type of the argument. */
683int countlsuk (unsigned accum val);
684
685/** \ingroup avr_stdfix
686 - If \p val is non-zero, the return value is the largest integer
687 \c k for which the expression <tt>val &lt;&lt; k</tt> does not overflow.
688 - If \p val is zero, an integer value is returned that is at least
689 as large as <tt>N - 1</tt>, where <tt>N</tt> is the total number
690 of bits of the type of the argument. */
691int countlslk (long accum val);
692
693/** \ingroup avr_stdfix
694 - If \p val is non-zero, the return value is the largest integer
695 \c k for which the expression <tt>val &lt;&lt; k</tt> does not overflow.
696 - If \p val is zero, an integer value is returned that is at least
697 as large as <tt>N - 1</tt>, where <tt>N</tt> is the total number
698 of bits of the type of the argument. */
699int countlsulk (unsigned long accum val);
700
701/** \ingroup avr_stdfix
702 - If \p val is non-zero, the return value is the largest integer
703 \c k for which the expression <tt>val &lt;&lt; k</tt> does not overflow.
704 - If \p val is zero, an integer value is returned that is at least
705 as large as <tt>N - 1</tt>, where <tt>N</tt> is the total number
706 of bits of the type of the argument. */
707int countlsllk (long long accum val);
708
709/** \ingroup avr_stdfix
710 - If \p val is non-zero, the return value is the largest integer
711 \c k for which the expression <tt>val &lt;&lt; k</tt> does not overflow.
712 - If \p val is zero, an integer value is returned that is at least
713 as large as <tt>N - 1</tt>, where <tt>N</tt> is the total number
714 of bits of the type of the argument. */
715int countlsullk (unsigned long long accum val);
716
717#endif /* Doxygen */
718
719/*
720 * The functions below compute the result of the multiplication or division
721 * operation on the operands with the indicated types, and return a value with
722 * the indicated type. The return value is rounded towards zero, and is
723 * saturated on overflow. If the second operand of one of the divide
724 * functions is zero, the behavior is undefined.
725 */
726
727/** \name Division */
728
729/** \ingroup avr_stdfix
730 The rdivi() function computes the value \c num/denom and returns the
731 result of the \c fract type.
732 The return value is rounded towards zero, and is saturated on overflow.
733 If \c denom is zero, the behavior is undefined.
734 \since AVR-LibC v2.3
735*/
736__ATTR_CONST__
737extern fract rdivi (int num, int denom);
738
739/** \ingroup avr_stdfix
740 The lrdivi() function computes the value of \c num/denom and returns the
741 result of the long fract type.
742 The return value is rounded towards zero, and is saturated on overflow.
743 If \c denom is zero, the behavior is undefined.
744 \since AVR-LibC v2.3
745*/
746__ATTR_CONST__
747extern long fract lrdivi (long int num, long int denom);
748
749/** \ingroup avr_stdfix
750 The urdivi() function computes the value \c num/denom and returns the
751 result of the \c unsigned \c fract type.
752 The return value is rounded towards zero, and is saturated on overflow.
753 If \c denom is zero, the behavior is undefined.
754 \since AVR-LibC v2.3
755*/
756__ATTR_CONST__
757extern unsigned fract urdivi (unsigned int num, unsigned int denom);
758
759/** \ingroup avr_stdfix
760 The ulrdivi() function computes the value of \c num/denom and returns the
761 result of the <tt>unsigned long fract</tt> type.
762 The return value is rounded towards zero, and is saturated on overflow.
763 If \c denom is zero, the behavior is undefined.
764 \since AVR-LibC v2.3
765*/
766__ATTR_CONST__
767extern unsigned long fract
768ulrdivi (unsigned long int num, unsigned long int denom);
769
770
771/* AVR-LibC extensions for mathematical functions on fixed-point numbers. */
772
773/* Fixed-point square roots using integer arithmetics.
774 * See "Fast Integer Square Root" by Ross M. Fosler, Microchip DS91040 (2000).
775 */
776
777#ifdef __DOXYGEN__
778/** \name Rounding */
779
780/** \ingroup avr_stdfix
781 Round \p val to \p bit fractional bits. When the result does not
782 fit into the range of the return type, the result is saturated. */
783short fract roundhr (short fract val, int bit);
784
785/** \ingroup avr_stdfix
786 Round \p val to \p bit fractional bits. When the result does not
787 fit into the range of the return type, the result is saturated. */
788unsigned short fract rounduhr (unsigned short fract val, int bit);
789
790/** \ingroup avr_stdfix
791 Round \p val to \p bit fractional bits. When the result does not
792 fit into the range of the return type, the result is saturated. */
793fract roundr (fract val, int bit);
794
795/** \ingroup avr_stdfix
796 Round \p val to \p bit fractional bits. When the result does not
797 fit into the range of the return type, the result is saturated. */
798unsigned fract roundur (unsigned fract val, int bit);
799
800/** \ingroup avr_stdfix
801 Round \p val to \p bit fractional bits. When the result does not
802 fit into the range of the return type, the result is saturated. */
803long fract roundlr (long fract val, int bit);
804
805/** \ingroup avr_stdfix
806 Round \p val to \p bit fractional bits. When the result does not
807 fit into the range of the return type, the result is saturated. */
808unsigned long fract roundulr (unsigned long fract val, int bit);
809
810/** \ingroup avr_stdfix
811 Round \p val to \p bit fractional bits. When the result does not
812 fit into the range of the return type, the result is saturated. */
813long long fract roundllr (long long fract val, int bit);
814
815/** \ingroup avr_stdfix
816 Round \p val to \p bit fractional bits. When the result does not
817 fit into the range of the return type, the result is saturated. */
818unsigned long long fract roundullr (unsigned long long fract val, int bit);
819
820/** \ingroup avr_stdfix
821 Round \p val to \p bit fractional bits. When the result does not
822 fit into the range of the return type, the result is saturated.
823
824 As an extension, \p bit may be in the range
825 <tt>&minus;IBIT &lt; bit &lt; FBIT</tt>.
826 For example, <tt>bit = &minus;1</tt> rounds to an even value. */
827short accum roundhk (short accum val, int bit);
828
829/** \ingroup avr_stdfix
830 Round \p val to \p bit fractional bits. When the result does not
831 fit into the range of the return type, the result is saturated.
832
833 As an extension, \p bit may be in the range
834 <tt>&minus;IBIT &lt; bit &lt; FBIT</tt>.
835 For example, <tt>bit = &minus;1</tt> rounds to an even value. */
836unsigned short accum rounduhk (unsigned short accum val, int bit);
837
838/** \ingroup avr_stdfix
839 Round \p val to \p bit fractional bits. When the result does not
840 fit into the range of the return type, the result is saturated.
841
842 As an extension, \p bit may be in the range
843 <tt>&minus;IBIT &lt; bit &lt; FBIT</tt>.
844 For example, <tt>bit = &minus;1</tt> rounds to an even value. */
845accum roundk (accum val, int bit);
846
847/** \ingroup avr_stdfix
848 Round \p val to \p bit fractional bits. When the result does not
849 fit into the range of the return type, the result is saturated.
850
851 As an extension, \p bit may be in the range
852 <tt>&minus;IBIT &lt; bit &lt; FBIT</tt>.
853 For example, <tt>bit = &minus;1</tt> rounds to an even value. */
854unsigned accum rounduk (unsigned accum val, int bit);
855
856/** \ingroup avr_stdfix
857 Round \p val to \p bit fractional bits. When the result does not
858 fit into the range of the return type, the result is saturated.
859
860 As an extension, \p bit may be in the range
861 <tt>&minus;IBIT &lt; bit &lt; FBIT</tt>.
862 For example, <tt>bit = &minus;1</tt> rounds to an even value. */
863long accum roundlk (long accum val, int bit);
864
865/** \ingroup avr_stdfix
866 Round \p val to \p bit fractional bits. When the result does not
867 fit into the range of the return type, the result is saturated.
868
869 As an extension, \p bit may be in the range
870 <tt>&minus;IBIT &lt; bit &lt; FBIT</tt>.
871 For example, <tt>bit = &minus;1</tt> rounds to an even value. */
872unsigned long accum roundulk (unsigned long accum val, int bit);
873
874/** \ingroup avr_stdfix
875 Round \p val to \p bit fractional bits. When the result does not
876 fit into the range of the return type, the result is saturated.
877
878 As an extension, \p bit may be in the range
879 <tt>&minus;IBIT &lt; bit &lt; FBIT</tt>.
880 For example, <tt>bit = &minus;1</tt> rounds to an even value. */
881long long accum roundllk (long long accum val, int bit);
882
883/** \ingroup avr_stdfix
884 Round \p val to \p bit fractional bits. When the result does not
885 fit into the range of the return type, the result is saturated.
886
887 As an extension, \p bit may be in the range
888 <tt>&minus;IBIT &lt; bit &lt; FBIT</tt>.
889 For example, <tt>bit = &minus;1</tt> rounds to an even value. */
890unsigned long long accum roundullk (unsigned long long accum val, int bit);
891
892
893/** \name Square Root and Transcendental Functions */
894
895/** \ingroup avr_stdfix
896 Compute the arcus cosine of \p x.
897 The returned value is in the range [0, &pi;].
898 For invalid values of \p x the returned value
899 is &minus;65536 = #kbits (0x80000000).
900
901 The absolute error is bounded by 5.5&middot;10<sup>&minus;5</sup>&nbsp;&asymp;&nbsp;2<sup>&minus;14.1</sup>.
902
903 \since AVR-LibC v2.3 */
904accum acosk (accum x);
905
906/** \ingroup avr_stdfix
907 Compute the arcus cosine of \p x.
908 The returned value is in the range [0, &pi;/2].
909 For invalid values of \p x the returned value
910 is 32768 = #ukbits (0x80000000).
911
912 The absolute error is bounded by 4.6&middot;10<sup>&minus;5</sup>&nbsp;&asymp;&nbsp;2<sup>&minus;14.4</sup>.
913
914 \since AVR-LibC v2.3 */
915unsigned accum acosuk (unsigned accum x);
916
917/** \ingroup avr_stdfix
918 Compute the arcus sine of \p x.
919 The returned value is in the range [&minus;&pi;/2, &pi;/2].
920 For invalid values of \p x the returned value
921 is &minus;65536 = #kbits (0x80000000).
922
923 The absolute error is bounded by 5.1&middot;10<sup>&minus;5</sup>&nbsp;&asymp;&nbsp;2<sup>&minus;14</sup>.
924
925 \since AVR-LibC v2.3 */
926accum asink (accum x);
927
928/** \ingroup avr_stdfix
929 Compute the arcus sine of \p x.
930 The returned value is in the range [0, &pi;/2].
931 For invalid values of \p x the returned value
932 is 32768 = #ukbits (0x80000000).
933
934 The absolute error is bounded by 4.5&middot;10<sup>&minus;5</sup>&nbsp;&asymp;&nbsp;2<sup>&minus;14.4</sup>.
935
936 \since AVR-LibC v2.3 */
937unsigned accum asinuk (unsigned accum x);
938
939/** \ingroup avr_stdfix
940 Compute the arcus tangent of \p x.
941 The returned value is in the range (&minus;&pi;/2, &pi;/2&asymp;1.5708).
942
943 \since AVR-LibC v2.3 */
944accum atank (accum x);
945
946/** \ingroup avr_stdfix
947 Compute the arcus tangent of \p x.
948 The returned value is in the range [0, &pi;/2&asymp;1.5708).
949
950 \since AVR-LibC v2.3 */
951unsigned accum atanuk (unsigned accum x);
952
953/** \ingroup avr_stdfix
954 Compute the arcus tangent of \p x.
955 The returned value is in the range [0, &pi;/4&asymp;0.7854].
956
957 The absolute error is bounded by 2.6&middot;10<sup>&minus;5</sup>&nbsp;&asymp;&nbsp;2<sup>&minus;15</sup>.
958 The worst case execution time (WCET) is around 210 cycles when MUL is
959 available, and around 1000 cycles when MUL is not available
960 (measured with avr-gcc v15).
961 \since AVR-LibC v2.3 */
962unsigned fract atanur (unsigned fract x);
963
964/** \ingroup avr_stdfix
965 Compute 2<sup>x</sup> with saturation.
966
967 The WCET is at least the one of exp2m1ur().
968 \since AVR-LibC v2.3 */
969accum exp2k (accum x);
970
971/** \ingroup avr_stdfix
972 Compute 2<sup>x</sup> with saturation.
973
974 The WCET is at least the one of exp2m1ur().
975 \since AVR-LibC v2.3 */
976unsigned accum exp2uk (unsigned accum x);
977
978/** \ingroup avr_stdfix
979 Compute 2<sup>x</sup>&nbsp;&minus;&nbsp;1.
980 The returned value is in the range [0, 1).
981
982 The absolute error is bounded by 2.2&middot;10<sup>&minus;5</sup>&nbsp;&asymp;&nbsp;2<sup>&minus;15.4</sup>.
983 The worst case execution time (WCET) is around 200 cycles when MUL is
984 available, and around 1000 cycles when MUL is not available
985 (measured with avr-gcc v15).
986 \since AVR-LibC v2.3 */
987unsigned fract exp2m1ur (unsigned fract x);
988
989/** \ingroup avr_stdfix
990 Returns log<sub>2</sub>(\p x), the logarithm to base 2 of the value \p x.
991 The returned value for \p x = 0 is &minus;32768.
992
993 The absolute error is bounded by 4.5&middot;10<sup>&minus;5</sup>&nbsp;&asymp;&nbsp;2<sup>&minus;14.5</sup>.
994 The worst case execution time (WCET) is around 150 cycles more
995 than the WCET of log21pur().
996 \since AVR-LibC v2.3 */
997accum log2uk(unsigned accum x);
998
999/** \ingroup avr_stdfix
1000 Return log<sub>2</sub>(\p x), the logarithm to base 2 of the value \p x.
1001 The returned value for \p x = 0 is &minus;128.
1002
1003 The absolute error is bounded by 8&middot;10<sup>&minus;3</sup>&nbsp;&asymp;&nbsp;2<sup>&minus;7</sup>.
1004 The worst case execution time (WCET) is around 60 cycles plus
1005 the WCET of log21puhr().
1006 \since AVR-LibC v2.3 */
1007short accum log2uhk(unsigned short accum x);
1008
1009/** \ingroup avr_stdfix
1010 Return log<sub>2</sub>(1 + \p x),
1011 the logarithm to base 2 of the value 1 + \p x.
1012 The result is in the range [0, 1).
1013
1014 The absolute error is bounded by 4.3&middot;10<sup>&minus;3</sup>&nbsp;&asymp;&nbsp;2<sup>&minus;7.5</sup>.
1015 The worst case execution time (WCET) is around 25 cycles when MUL is
1016 available, and around 340 cycles when MUL is not available.
1017 \since AVR-LibC v2.3 */
1018unsigned short fract log21puhr(unsigned short fract x);
1019
1020/** \ingroup avr_stdfix
1021 Return log<sub>2</sub>(1 + \p x),
1022 the logarithm to base 2 of the value 1 + \p x.
1023 The result is in the range [0, 1).
1024
1025 The absolute error is bounded by 3&middot;10<sup>&minus;5</sup>&nbsp;&asymp;&nbsp;2<sup>&minus;15</sup>.
1026 The worst case execution time (WCET) is around 250 cycles when MUL is
1027 available, and around 1300 cycles when MUL is not available.
1028 \since AVR-LibC v2.3 */
1029unsigned fract log21pur(unsigned fract x);
1030
1031/** \ingroup avr_stdfix
1032 Cosine of \p x&middot;&pi;/2 radians.
1033
1034 The absolute error is bounded by 4.6&middot;10<sup>&minus;5</sup>&nbsp;&asymp;&nbsp;2<sup>&minus;14.4</sup>.
1035 The worst case execution time (WCET) is around 300 cycles when MUL is
1036 available, and around 1400 cycles when MUL is not available.
1037 \since AVR-LibC v2.3 */
1038accum cospi2k(accum deg);
1039
1040/** \ingroup avr_stdfix
1041 Sine of \p x&middot;&pi;/2 radians.
1042
1043 The absolute error is bounded by 4.6&middot;10<sup>&minus;5</sup>&nbsp;&asymp;&nbsp;2<sup>&minus;14.4</sup>.
1044 The worst case execution time (WCET) is around 300 cycles when MUL is
1045 available, and around 1400 cycles when MUL is not available.
1046 \since AVR-LibC v2.3 */
1047accum sinpi2k(accum deg);
1048
1049/** \ingroup avr_stdfix
1050 Sine of the angle \a deg where \a deg is specified in degrees, i.e.
1051 in the range [0&deg;, 256&deg;).
1052 The returned value is in the range (&minus;1, +1), i.e. is never &minus;1.
1053
1054 The absolute error is bounded by 6.5&middot;10<sup>&minus;5</sup>&nbsp;&asymp;&nbsp;2<sup>&minus;13.9</sup>.
1055 The worst case execution time (WCET) is around 70 cycles.
1056 \since AVR-LibC v2.3 */
1057fract sinuhk_deg(unsigned short accum deg);
1058
1059/** \ingroup avr_stdfix
1060 Cosine of the angle \a deg where \a deg is specified in degrees, i.e.
1061 in the range [0&deg;, 256&deg;).
1062 The returned value is in the range (&minus;1, +1), i.e. is never &minus;1.
1063
1064 The absolute error is bounded by 6.5&middot;10<sup>&minus;5</sup>&nbsp;&asymp;&nbsp;2<sup>&minus;13.9</sup>.
1065 The worst case execution time (WCET) is around 90 cycles.
1066 \since AVR-LibC v2.3 */
1067fract cosuhk_deg(unsigned short accum deg);
1068
1069/** \ingroup avr_stdfix
1070 Sine of \p x&middot;&pi;/2 radians.
1071 The returned value is in the range [0, 1).
1072
1073 The absolute error is bounded by 2.9&middot;10<sup>&minus;5</sup>&nbsp;&asymp;&nbsp;2<sup>&minus;15</sup>.
1074 The worst case execution time (WCET) is around 260 cycles when MUL is
1075 available, and around 1400 cycles when MUL is not available.
1076 \since AVR-LibC v2.3 */
1077unsigned fract sinpi2ur(unsigned fract x);
1078
1079/** \ingroup avr_stdfix
1080 Square root of the value \p radic rounded down.
1081 \since AVR-LibC v2.3 */
1082short fract sqrthr(short fract radic);
1083
1084/** \ingroup avr_stdfix
1085 Square root of the value \p radic rounded down.
1086 The result is in the range [0, 1).
1087
1088 The absolute error is in the range [&minus;3.9&middot;10<sup>&minus;3</sup>&nbsp;&asymp;&nbsp;2<sup>&minus;8</sup>, 0].
1089 The worst case execution time (WCET) is around 120 cycles.
1090 \since AVR-LibC v2.3 */
1091unsigned short fract sqrtuhr(unsigned short fract radic);
1092
1093/** \ingroup avr_stdfix
1094 Square root of the value \p radic. The result is in the range [0, 1).
1095
1096 The absolute error is in the range [&minus;1.5&middot;10<sup>&minus;5</sup>&nbsp;&asymp;&nbsp;2<sup>&minus;16</sup>, 0].
1097 The worst case execution time (WCET) is around 320 cycles.
1098 \since AVR-LibC v2.3 */
1099unsigned fract sqrtur(unsigned fract radic);
1100
1101
1102/** \name Type-Generic Functions */
1103
1104/** \ingroup avr_stdfix
1105 Computes the absolute value of fixed-point value \p val.
1106 When the result does not fit into the range of the return type,
1107 the result is saturated. */
1108type absfx (type val);
1109
1110/** \ingroup avr_stdfix
1111 - If \p val is non-zero, the return value is the largest integer
1112 \c k for which the expression <tt>val &lt;&lt; k</tt> does not overflow.
1113 - If \p val is zero, an integer value is returned that is at least
1114 as large as <tt>N - 1</tt>, where <tt>N</tt> is the total number
1115 of bits of the type of the argument. */
1116int countlsfx (type val);
1117
1118/** \ingroup avr_stdfix
1119 Round \p val to \p bit fractional bits. When the result does not
1120 fit into the range of the return type, the result is saturated.
1121
1122 As an extension, \p bit may be in the range
1123 <tt>&minus;IBIT &lt; bit &lt; FBIT</tt>.
1124 For example, <tt>bit = &minus;1</tt> rounds to an even value. */
1125type roundfx (type val, int bit);
1126
1127#else /* Doxygen */
1128extern unsigned accum acosuk(unsigned accum) __ATTR_CONST__;
1129extern unsigned accum asinuk(unsigned accum) __ATTR_CONST__;
1130extern unsigned accum atanuk(unsigned accum) __ATTR_CONST__;
1131extern accum acosk(accum) __ATTR_CONST__;
1132extern accum asink(accum) __ATTR_CONST__;
1133extern accum atank(accum) __ATTR_CONST__;
1134extern unsigned fract atanur(unsigned fract) __ATTR_CONST__;
1135
1136extern short fract sqrthr(short fract) __asm__("__sqrthr") __ATTR_CONST__;
1137extern unsigned short fract sqrtuhr(unsigned short fract) __asm__("__sqrtuhr") __ATTR_CONST__;
1138unsigned fract sqrtur(unsigned fract) __ATTR_CONST__;
1139
1140extern unsigned short fract log21puhr(unsigned short fract) __ATTR_CONST__;
1141extern unsigned fract log21pur(unsigned fract) __ATTR_CONST__;
1142extern accum log2uk(unsigned accum) __ATTR_CONST__;
1143extern short accum log2uhk(unsigned short accum) __ATTR_CONST__;
1144
1145extern fract sinuhk_deg(unsigned short accum) __ATTR_CONST__;
1146extern fract cosuhk_deg(unsigned short accum) __ATTR_CONST__;
1147extern unsigned fract sinpi2ur(unsigned fract) __ATTR_CONST__;
1148extern accum sinpi2k(accum) __ATTR_CONST__;
1149extern accum cospi2k(accum) __ATTR_CONST__;
1150
1151extern accum exp2k (accum) __ATTR_CONST__;
1152extern unsigned accum exp2uk (unsigned accum) __ATTR_CONST__;
1153extern unsigned fract exp2m1ur (unsigned fract) __ATTR_CONST__;
1154
1155extern char* uktoa (unsigned accum, char*, unsigned char);
1156extern char* urtoa (unsigned fract, char*, unsigned char);
1157extern char* ktoa (accum, char*, unsigned char);
1158extern char* rtoa (fract, char*, unsigned char);
1159extern char* uhktoa (unsigned short accum, char*, unsigned char);
1160extern char* uhrtoa (unsigned short fract, char*, unsigned char);
1161extern char* hktoa (short accum, char*, unsigned char);
1162extern char* hrtoa (short fract, char*, unsigned char);
1163#endif /* Doxygen */
1164
1165#ifdef __cplusplus
1166}
1167#endif
1168
1169#endif /* _STDFIX_AVRLIBC_H */
accum roundk(accum val, int bit)
unsigned long long fract ullrbits(unsigned long long val)
long long fract absllr(long long fract val)
long accum lkbits(long long val)
long accum abslk(long accum val)
long fract roundlr(long fract val, int bit)
long accum roundlk(long accum val, int bit)
unsigned long fract roundulr(unsigned long fract val, int bit)
long long accum roundllk(long long accum val, int bit)
int countlsulk(unsigned long accum val)
unsigned long long bitsullr(unsigned long long fract val)
char * uktoa(unsigned accum x, char *buf, unsigned char mode)
char * rtoa(fract x, char *buf, unsigned char mode)
unsigned short fract uhrbits(unsigned char val)
int bitshk(short accum val)
int countlshk(short accum val)
accum cospi2k(accum deg)
unsigned short fract log21puhr(unsigned short fract x)
unsigned long bitsuk(unsigned accum val)
unsigned int bitsur(unsigned fract val)
long bitsk(accum val)
unsigned short accum rounduhk(unsigned short accum val, int bit)
unsigned long long bitsullk(unsigned long long accum val)
short fract abshr(short fract val)
int countlshr(short fract val)
int countlsuhr(unsigned short fract val)
fract roundr(fract val, int bit)
long long bitsllk(long long accum val)
unsigned fract sqrtur(unsigned fract radic)
short accum abshk(short accum val)
char * urtoa(unsigned fract x, char *buf, unsigned char mode)
unsigned long accum ulkbits(unsigned long long val)
accum atank(accum x)
short accum hkbits(int val)
int countlslr(long fract val)
unsigned fract urdivi(unsigned int num, unsigned int denom)
int countlsllr(long long fract val)
long fract lrbits(long val)
short fract sqrthr(short fract radic)
int countlsk(accum val)
unsigned long long accum ullkbits(unsigned long long val)
long fract lrdivi(long int num, long int denom)
unsigned short accum uhkbits(unsigned int val)
long long fract roundllr(long long fract val, int bit)
long bitslr(long fract val)
unsigned short fract rounduhr(unsigned short fract val, int bit)
short accum log2uhk(unsigned short accum x)
accum exp2k(accum x)
int countlsuk(unsigned accum val)
fract sinuhk_deg(unsigned short accum deg)
unsigned long long fract roundullr(unsigned long long fract val, int bit)
unsigned long bitsulr(unsigned long fract val)
char * ktoa(accum x, char *buf, unsigned char mode)
accum sinpi2k(accum deg)
type roundfx(type val, int bit)
long long accum llkbits(long long val)
char * hrtoa(short fract x, char *buf, unsigned char mode)
int countlslk(long accum val)
int countlsulr(unsigned long fract val)
int countlsur(unsigned fract val)
unsigned accum acosuk(unsigned accum x)
accum absk(accum val)
unsigned accum ukbits(unsigned long val)
signed char bitshr(short fract val)
unsigned accum rounduk(unsigned accum val, int bit)
short fract hrbits(signed char val)
fract absr(fract val)
fract rbits(int val)
char * uhrtoa(unsigned short fract x, char *buf, unsigned char mode)
short fract roundhr(short fract val, int bit)
unsigned long long bitsulk(unsigned long accum val)
int countlsullk(unsigned long long accum val)
long long bitslk(long accum val)
unsigned short fract sqrtuhr(unsigned short fract radic)
long long accum absllk(long long accum val)
unsigned char bitsuhr(unsigned short fract val)
char * uhktoa(unsigned short accum x, char *buf, unsigned char mode)
long fract abslr(long fract val)
char * hktoa(short accum x, char *buf, unsigned char mode)
accum log2uk(unsigned accum x)
unsigned long accum roundulk(unsigned long accum val, int bit)
int countlsllk(long long accum val)
unsigned int bitsuhk(unsigned short accum val)
int countlsullr(unsigned long long fract val)
long long fract llrbits(long long val)
type absfx(type val)
int countlsuhk(unsigned short accum val)
unsigned fract atanur(unsigned fract x)
unsigned accum exp2uk(unsigned accum x)
fract cosuhk_deg(unsigned short accum deg)
fract rdivi(int num, int denom)
int countlsr(fract val)
unsigned long fract ulrbits(unsigned long val)
unsigned fract exp2m1ur(unsigned fract x)
accum kbits(long val)
unsigned accum atanuk(unsigned accum x)
unsigned long long accum roundullk(unsigned long long accum val, int bit)
unsigned fract sinpi2ur(unsigned fract x)
accum acosk(accum x)
accum asink(accum x)
long long bitsllr(long long fract val)
int bitsr(fract val)
unsigned long fract ulrdivi(unsigned long int num, unsigned long int denom)
unsigned fract log21pur(unsigned fract x)
unsigned fract roundur(unsigned fract val, int bit)
unsigned accum asinuk(unsigned accum x)
int countlsfx(type val)
unsigned fract urbits(unsigned int val)
short accum roundhk(short accum val, int bit)