Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

# fixedpt.h

Go to the documentation of this file.

    00001 /*! \file fixedpt.h \brief Fixed-point math function library. */
    00002 //*****************************************************************************
    00003 //
    00004 // File Name    : 'fixedpt.h'
    00005 // Title        : Fixed-point math function library
    00006 // Author       : Pascal Stang - Copyright (C) 2003
    00007 // Created      : 2003.01.26
    00008 // Revised      : 2003.02.04
    00009 // Version      : 0.1
    00010 // Target MCU   : Atmel AVR Series
    00011 // Editor Tabs  : 4
    00012 //
    00013 // NOTE: This code is currently below version 1.0, and therefore is considered
    00014 // to be lacking in some functionality or documentation, or may not be fully
    00015 // tested.  Nonetheless, you can expect most functions to work.
    00016 //
    00017 /// \ingroup general
    00018 /// \defgroup fixedpt Fixed-Point Math Function Library (fixedpt.c)
    00019 /// \code #include "fixedpt.h" \endcode
    00020 /// \par Overview
    00021 ///     This library provides basic fixed-point math operations implemented in
    00022 ///     C. Fixed-point math is a system by which integer variables can
    00023 ///     represent fractional values with a fixed precision "behind" the decimal
    00024 ///     point (like a fixed number of decimal places).  Fixed-point math is
    00025 ///     typically 10x faster to execute than floating-point math, and should
    00026 ///     be used when a limited amount of fractional precision is sufficient
    00027 ///     (such as 4ths, or 10ths, or 128ths, etc).
    00028 ///
    00029 ///     \note This library is really meant more as a demonstration of fixed-pt
    00030 ///     math.  For best code-efficiency and speed, you are enouraged to take
    00031 ///     the code you see in these functions and copy it into your own code.
    00032 //
    00033 // This code is distributed under the GNU Public License
    00034 //      which can be found at http://www.gnu.org/licenses/gpl.txt
    00035 //
    00036 //*****************************************************************************
    00037
    00038 #ifndef FIXEDPT_H
    00039 #define FIXEDPT_H
    00040
    00041 #include "global.h"
    00042
    00043 // constants/macros/typdefs
    00044
    00045 // functions
    00046
    00047 //! fixedptInit() initializes fixed-point math function library
    00048 //   set the number of bits to use behind the point
    00049 void fixedptInit(u08 fixedPtBits);
    00050
    00051 //! convert integer to fixed-point number
    00052 s32 fixedptConvertFromInt(s32 int_number);
    00053
    00054 //! convert fixed-point number to integer
    00055 s32 fixedptConvertToInt(s32 fp_number);
    00056
    00057 //! add a and b (a+b) with fixed-point math
    00058 s32 fixedptAdd(s32 a, s32 b);
    00059
    00060 //! subtract a and b (a-b) with fixed-point math
    00061 s32 fixedptSubtract(s32 a, s32 b);
    00062
    00063 //! multiply a and b (a*b) with fixed-point math
    00064 s32 fixedptMultiply(s32 a, s32 b);
    00065
    00066 //! divide numer by denom (numer/denom) with fixed-point math
    00067 s32 fixedptDivide(s32 numer, s32 denom);
    00068
    00069 #endif