[ 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 (int v) | |
FixedPoint (int v, FixedPointNoShift) | |
FixedPoint (double rhs) | |
FixedPoint (const FixedPoint &other) | |
template<unsigned Int2, unsigned Frac2> | |
FixedPoint (const FixedPoint< Int2, Frac2 > &other) | |
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= (int rhs) |
FixedPoint & | operator= (double rhs) |
FixedPoint & | operator= (const FixedPoint &other) |
template<unsigned Int2, unsigned Frac2> | |
FixedPoint & | operator= (const FixedPoint< Int2, Frac2 > &other) |
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:
#include <vigra/fixedpoint.hxx>
Namespace: vigra
|
explicit |
Construct from an int (fractional part will become zero).
FixedPoint | ( | int | v, |
FixedPointNoShift | |||
) |
Construct from an int by a bitwise copy. This is normally only used internally.
|
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 | ( | const FixedPoint< IntBits, FractionalBits > & | other | ) |
Copy constructor.
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.
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.
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.
FixedPoint& operator= | ( | const FixedPoint< IntBits, FractionalBits > & | other | ) |
Copy assignment.
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.
FixedPoint operator- | ( | ) | const |
Negation.
FixedPoint& operator++ | ( | ) |
Pre-increment.
FixedPoint operator++ | ( | int | ) |
Post-increment.
FixedPoint& operator-- | ( | ) |
Pre-decrement.
FixedPoint operator-- | ( | int | ) |
Post-decrement.
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.
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.
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.
© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) |
html generated using doxygen and Python
|