[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

FixedPoint< IntBits, FractionalBits > Class Template Reference

`#include <vigra/fixedpoint.hxx>`

## Public Member Functions

| FixedPoint (const FixedPoint &other)
template<unsigned Int2, unsigned Frac2>
| FixedPoint (const FixedPoint< Int2, Frac2 > &other)
| FixedPoint (double rhs)
| FixedPoint (int v)
| FixedPoint (int v, FixedPointNoShift)
template<unsigned Int2, unsigned Frac2>
FixedPoint & | operator*= (const FixedPoint< Int2, Frac2 > &other)
FixedPoint & | operator++ ()
FixedPoint | operator++ (int)
template<unsigned Int2, unsigned Frac2>
FixedPoint & | operator+= (const FixedPoint< Int2, Frac2 > &other)
FixedPoint | operator- () const
FixedPoint & | operator-- ()
FixedPoint | operator-- (int)
template<unsigned Int2, unsigned Frac2>
FixedPoint & | operator-= (const FixedPoint< Int2, Frac2 > &other)
FixedPoint & | operator= (const FixedPoint &other)
template<unsigned Int2, unsigned Frac2>
FixedPoint & | operator= (const FixedPoint< Int2, Frac2 > &other)
FixedPoint & | operator= (double rhs)
FixedPoint & | operator= (int rhs)

## Detailed Description

template<unsigned IntBits, unsigned FractionalBits>
class vigra::FixedPoint< IntBits, FractionalBits >

Template for fixed point arithmetic.

Fixed point arithmetic is used when computations with fractional accuracy must be made at the highest speed possible (e.g. in the inner loop of a volume rendering routine). The speed-up relative to floating point arithmetic can be dramatic, especially when one can avoid conversions between integer and floating point numbers (these are very expensive because integer and floating point arithmetic resides in different pipelines).

The template wraps an `int` and uses `IntBits` to represent the integral part of a number, and `FractionalBits` for the fractional part, where `IntBits + FractionalBits < 32`. (The 32rd bit is reserved because FixedPoint is a signed type). These numbers will be automatically allocated in an intelligent way in the result of an arithmetic operation. For example, when two fixed point numbers are multiplied, the required number of integer bits in the result is the sum of the number of integer bits of the arguments, but only when so many bits are available. This is figured out by means of FixedPointTraits, and a compile-time error is raised when no suitable representation can be found. The idea is that the right thing happens automatically as often as possible.

`FixedPoint` implements the required interface of an AlgebraicRing and the required numeric and promotion traits. In addition, it supports functions `add`, `sub`, and `mul`, where a particular layout of the result can be enforced.

`unsigned char, signed char, unsigned short, signed short, int` can be transformed into a FixedPoint with appropriate layout by means of the factory function `fixedPoint()`.

See also:

- Functions for FixedPoint
- Numeric and Promote Traits of FixedPoint

#include <vigra/fixedpoint.hxx>
Namespace: vigra

## Constructor & Destructor Documentation

## ◆ FixedPoint() [1/5]

template<unsigned IntBits, unsigned FractionalBits>

FixedPoint | ( | int | v | ) |

explicit

Construct from an int (fractional part will become zero).

## ◆ FixedPoint() [2/5]

template<unsigned IntBits, unsigned FractionalBits>

FixedPoint | ( | int | v,
|  | FixedPointNoShift |
| ) |  |

Construct from an int by a bitwise copy. This is normally only used internally.

## ◆ FixedPoint() [3/5]

template<unsigned IntBits, unsigned FractionalBits>

FixedPoint | ( | double | rhs | ) |

explicit

Construct from an double and round the fractional part to `FractionalBits` accuracy. A PreconditionViolation exception is raised when the integer part is too small to represent the number.

## ◆ FixedPoint() [4/5]

template<unsigned IntBits, unsigned FractionalBits>

FixedPoint | ( | const FixedPoint< IntBits, FractionalBits > & | other | ) |

Copy constructor.

## ◆ FixedPoint() [5/5]

template<unsigned IntBits, unsigned FractionalBits>
template<unsigned Int2, unsigned Frac2>

FixedPoint | ( | const FixedPoint< Int2, Frac2 > & | other | ) |

Construct from a FixedPoint with different layout. It rounds as appropriate and raises a compile-time error when the target type has too few integer bits.

## Member Function Documentation

## ◆ operator=() [1/4]

template<unsigned IntBits, unsigned FractionalBits>

FixedPoint & operator= | ( | int | rhs | ) |

Assignment from int. The fractional part will become zero. A PreconditionViolation exception is raised when the integer part is too small to represent the number.

## ◆ operator=() [2/4]

template<unsigned IntBits, unsigned FractionalBits>

FixedPoint & operator= | ( | double | rhs | ) |

Assignment form double. The fractional part is rounded, and a PreconditionViolation exception is raised when the integer part is too small to represent the number.

## ◆ operator=() [3/4]

template<unsigned IntBits, unsigned FractionalBits>

FixedPoint & operator= | ( | const FixedPoint< IntBits, FractionalBits > & | other | ) |

Copy assignment.

## ◆ operator=() [4/4]

template<unsigned IntBits, unsigned FractionalBits>
template<unsigned Int2, unsigned Frac2>

FixedPoint & operator= | ( | const FixedPoint< Int2, Frac2 > & | other | ) |

Assignment from a FixedPoint with different layout. It rounds as appropriate and raises a compile-time error when the target type has too few integer bits.

## ◆ operator-()

template<unsigned IntBits, unsigned FractionalBits>

FixedPoint operator- | ( |  | ) | const

Negation.

## ◆ operator++() [1/2]

template<unsigned IntBits, unsigned FractionalBits>

FixedPoint & operator++ | ( |  | ) |

Pre-increment.

## ◆ operator++() [2/2]

template<unsigned IntBits, unsigned FractionalBits>

FixedPoint operator++ | ( | int |  | ) |

Post-increment.

## ◆ operator--() [1/2]

template<unsigned IntBits, unsigned FractionalBits>

FixedPoint & operator-- | ( |  | ) |

Pre-decrement.

## ◆ operator--() [2/2]

template<unsigned IntBits, unsigned FractionalBits>

FixedPoint operator-- | ( | int |  | ) |

Post-decrement.

## ◆ operator+=()

template<unsigned IntBits, unsigned FractionalBits>
template<unsigned Int2, unsigned Frac2>

FixedPoint & operator+= | ( | const FixedPoint< Int2, Frac2 > & | other | ) |

Add-assignment from a FixedPoint with different layout. It rounds as appropriate and raises a compile-time error when the target type has too few integer bits.

## ◆ operator-=()

template<unsigned IntBits, unsigned FractionalBits>
template<unsigned Int2, unsigned Frac2>

FixedPoint & operator-= | ( | const FixedPoint< Int2, Frac2 > & | other | ) |

Subtract-assignment from a FixedPoint with different layout. It rounds as appropriate and raises a compile-time error when the target type has too few integer bits.

## ◆ operator*=()

template<unsigned IntBits, unsigned FractionalBits>
template<unsigned Int2, unsigned Frac2>

FixedPoint & operator*= | ( | const FixedPoint< Int2, Frac2 > & | other | ) |

Multiply-assignment from a FixedPoint with different layout. It rounds as appropriate and raises a compile-time error when the target type has too few integer bits.

The documentation for this class was generated from the following file:

- vigra/fixedpoint.hxx

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python vigra 1.12.2