Fixmath  1.4
fixmath.h
Go to the documentation of this file.
1 /* Copyright (C) 2005-2011, Axis Communications AB, LUND, SWEDEN
2  *
3  * This file is part of Fixmath.
4  *
5  * Fixmath is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published
7  * by the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  * You can use the comments under either the terms of the GNU Lesser General
10  * Public License version 3 as published by the Free Software Foundation,
11  * either version 3 of the License or (at your option) any later version, or
12  * the GNU Free Documentation License version 1.3 or any later version
13  * published by the Free Software Foundation; with no Invariant Sections, no
14  * Front-Cover Texts, and no Back-Cover Texts.
15  * A copy of the license is included in the documentation section entitled
16  * "GNU Free Documentation License".
17  *
18  * Fixmath is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public
24  * License and a copy of the GNU Free Documentation License along
25  * with Fixmath. If not, see <http://www.gnu.org/licenses/>.
26  */
27 
336 #ifndef FIXMATH_H
337 #define FIXMATH_H
338 
339 #include <stdint.h> /* Fixed-size integers */
340 #include "fixmath_arch.h" /* Platform-specific definitions */
341 #include "fixmath_export.h" /* Win32 DLL function visibility */
342 
343 #ifdef __cplusplus
344 extern "C" {
345 #endif
346 
347 /*
348  * -------------------------------------------------------------
349  * Type definitions
350  * -------------------------------------------------------------
351  */
352 
356 typedef int32_t fixed_t;
357 
362 typedef struct {
363  int32_t mant;
364  int expn;
365 } fx_rdiv_t;
366 
367 
368 /*
369  * -------------------------------------------------------------
370  * Bit manipulation functions
371  * -------------------------------------------------------------
372  */
373 
381 #ifndef fx_clz
382 FX_EXPORT int
383 fx_clz(uint32_t word);
384 #endif /* !fx_clz */
385 
393 #ifndef fx_ctz
394 FX_EXPORT int
395 fx_ctz(uint32_t word);
396 #endif /* !fx_ctz */
397 
403 #ifndef fx_bitcount
404 FX_EXPORT int
405 fx_bitcount(uint32_t word);
406 #endif /* !fx_bitcount */
407 
408 
409 /*
410  * -------------------------------------------------------------
411  * Fixed-point arithmetic and conversions
412  * -------------------------------------------------------------
413  */
414 
422 FX_EXPORT fixed_t
423 fx_itox(int32_t ival, unsigned frac);
424 
434 FX_EXPORT fixed_t
435 fx_ftox(float fval, unsigned frac);
436 
446 FX_EXPORT fixed_t
447 fx_dtox(double dval, unsigned frac);
448 
458 FX_EXPORT fixed_t
459 fx_xtox(fixed_t xval, unsigned frac1, unsigned frac2);
460 
469 FX_EXPORT int32_t
470 fx_xtoi(fixed_t xval, unsigned frac);
471 
480 FX_EXPORT float
481 fx_xtof(fixed_t xval, unsigned frac);
482 
491 FX_EXPORT double
492 fx_xtod(fixed_t xval, unsigned frac);
493 
502 FX_EXPORT int32_t
503 fx_roundx(fixed_t xval, unsigned frac);
504 
515 FX_EXPORT int32_t
516 fx_ceilx(fixed_t xval, unsigned frac);
517 
527 FX_EXPORT int32_t
528 fx_floorx(fixed_t xval, unsigned frac);
529 
540 FX_EXPORT fixed_t
541 fx_addx(fixed_t x1, fixed_t x2);
542 
553 FX_EXPORT fixed_t
554 fx_subx(fixed_t x1, fixed_t x2);
555 
569 FX_EXPORT fixed_t
570 fx_mulx(fixed_t x1, fixed_t x2, unsigned frac);
571 
584 FX_EXPORT fixed_t
585 fx_divx(fixed_t x1, fixed_t x2, unsigned frac);
586 
597 FX_EXPORT fixed_t
598 fx_rdivx(fixed_t xval, const fx_rdiv_t *rdiv);
599 
600 
601 /*
602  * -------------------------------------------------------------
603  * String conversion functions
604  * -------------------------------------------------------------
605  */
606 
617 FX_EXPORT int
618 fx_itoa(char *str, int32_t val);
619 
635 FX_EXPORT int
636 fx_xtoa(char *str, fixed_t xval, unsigned frac, unsigned digits);
637 
638 
639 /*
640  * -------------------------------------------------------------
641  * Algebraic functions
642  * -------------------------------------------------------------
643  */
644 
655 FX_EXPORT fixed_t
656 fx_invx(fixed_t xval, unsigned frac, fx_rdiv_t *rdiv);
657 
667 FX_EXPORT fixed_t
668 fx_sqrtx(fixed_t xval, unsigned frac);
669 
681 FX_EXPORT fixed_t
682 fx_isqrtx(fixed_t xval, unsigned frac, fx_rdiv_t *rdiv);
683 
684 
685 /*
686  * -------------------------------------------------------------
687  * Transcendental functions
688  * -------------------------------------------------------------
689  */
690 
699 FX_EXPORT fixed_t
700 fx_expx(fixed_t xval, unsigned frac);
701 
710 FX_EXPORT fixed_t
711 fx_exp2x(fixed_t xval, unsigned frac);
712 
721 FX_EXPORT fixed_t
722 fx_exp10x(fixed_t xval, unsigned frac);
723 
733 FX_EXPORT fixed_t
734 fx_logx(fixed_t xval, unsigned frac);
735 
745 FX_EXPORT fixed_t
746 fx_log2x(fixed_t xval, unsigned frac);
747 
757 FX_EXPORT fixed_t
758 fx_log10x(fixed_t xval, unsigned frac);
759 
775 FX_EXPORT fixed_t
776 fx_powx(fixed_t xval, unsigned xfrac, fixed_t yval, unsigned yfrac);
777 
787 FX_EXPORT fixed_t
788 fx_sinx(fixed_t xval, unsigned frac);
789 
799 FX_EXPORT fixed_t
800 fx_cosx(fixed_t xval, unsigned frac);
801 
802 
803 #include "fixmath_impl.h" /* Internal implementations */
804 #include "fixmath_macro.h" /* Macro overrides */
805 
806 #ifdef __cplusplus
807 };
808 #endif
809 
810 #endif /* FIXMATH_H */
811 
int fx_ctz(uint32_t word)
fixed_t fx_logx(fixed_t xval, unsigned frac)
Definition: fixmath.h:362
fixed_t fx_exp10x(fixed_t xval, unsigned frac)
fixed_t fx_addx(fixed_t x1, fixed_t x2)
fixed_t fx_dtox(double dval, unsigned frac)
int32_t fx_ceilx(fixed_t xval, unsigned frac)
fixed_t fx_invx(fixed_t xval, unsigned frac, fx_rdiv_t *rdiv)
int fx_bitcount(uint32_t word)
fixed_t fx_divx(fixed_t x1, fixed_t x2, unsigned frac)
int32_t fx_xtoi(fixed_t xval, unsigned frac)
fixed_t fx_isqrtx(fixed_t xval, unsigned frac, fx_rdiv_t *rdiv)
fixed_t fx_ftox(float fval, unsigned frac)
fixed_t fx_subx(fixed_t x1, fixed_t x2)
int fx_xtoa(char *str, fixed_t xval, unsigned frac, unsigned digits)
fixed_t fx_powx(fixed_t xval, unsigned xfrac, fixed_t yval, unsigned yfrac)
int fx_clz(uint32_t word)
int32_t fixed_t
Definition: fixmath.h:356
fixed_t fx_log10x(fixed_t xval, unsigned frac)
double fx_xtod(fixed_t xval, unsigned frac)
Fixed-point math library - platform-specific definitions.
fixed_t fx_itox(int32_t ival, unsigned frac)
fixed_t fx_sqrtx(fixed_t xval, unsigned frac)
fixed_t fx_cosx(fixed_t xval, unsigned frac)
fixed_t fx_log2x(fixed_t xval, unsigned frac)
fixed_t fx_mulx(fixed_t x1, fixed_t x2, unsigned frac)
fixed_t fx_exp2x(fixed_t xval, unsigned frac)
fixed_t fx_rdivx(fixed_t xval, const fx_rdiv_t *rdiv)
int32_t fx_floorx(fixed_t xval, unsigned frac)
fixed_t fx_expx(fixed_t xval, unsigned frac)
fixed_t fx_sinx(fixed_t xval, unsigned frac)
fixed_t fx_xtox(fixed_t xval, unsigned frac1, unsigned frac2)
Fixed-point math library - function-like macros.
float fx_xtof(fixed_t xval, unsigned frac)
int32_t fx_roundx(fixed_t xval, unsigned frac)
int fx_itoa(char *str, int32_t val)