Into

Modules

Documentation

classPiiFixedPoint

#include <PiiFixedPoint.h>

A replacement for float/double numbers.

Description

In some occasions, computations are performed faster with fixed point than with floating point numbers. The speed gain is, however, very dependent on processor architecture. In general, fixed point addition and subtraction are always faster, but the same does not necessarily apply to multiplication and division. The Pentium processor, for example, performs floating point multiplication and division faster than their integer correspondents. The downside is that floating point calculations cannot be fully pipelined. Thus, consequtive fixed multiplications may end up to be faster. Converting a fixed point number back to a float costs a division. Therefore, consider your requirements carefully.

The decimals template parameter tell the number of decimal bits. Typically, half of the data type is used (16 for int on PC). Use the number to tune the trade-off between precision and range.

Constructors and destructor

(
  • T value
  • int shift = decimals
)

Initialize with an integer value.

Initialize the fixed point value to zero.

( )

Copy constructor.

(
  • double value
)

Initialize the fixed point number with a floating point value.

Public member functions

( )
void
( )
( )
void
( )
( )
void
( )
( )
void
( )

Function details

  • PiiFixedPoint

    (
    • T value
    • int shift = decimals
    )
    [inline]

    Initialize with an integer value.

    Parameters
    value

    the value as an integer

    shift

    the number of decimal bits to add to the number. value will be shifted this many times to the left.

  • PiiFixedPoint

    ()
    [inline]

    Initialize the fixed point value to zero.

  • PiiFixedPoint

    ( )
    [inline]

    Copy constructor.

  • PiiFixedPoint

    (
    • double value
    )
    [inline]

    Initialize the fixed point number with a floating point value.

    This may result in rounding errors.

  • operator double

    ()
    [inline]
  • operator float

    ()
    [inline]
  • PiiFixedPoint operator*

    ( )
    [inline]
  • void operator*=

    ( )
    [inline]
  • PiiFixedPoint operator+

    ( )
    [inline]
  • void operator+=

    ( )
    [inline]
  • PiiFixedPoint operator-

    ( )
    [inline]
  • void operator-=

    ( )
    [inline]
  • PiiFixedPoint operator/

    ( )
    [inline]
  • void operator/=

    ( )
    [inline]
Notes (0)

Add a note

Not a single note added yet. Be the first, add yours.