vigra - FixedPoint16< IntBits, OverflowHandling > Class Template Reference

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

| FixedPoint16< IntBits, OverflowHandling > Class Template Reference |

`#include <vigra/fixedpoint.hxx>`

## Public Member Functions
| FixedPoint16 (Int32 v)
| FixedPoint16 (Int32 v, FixedPointNoShift)
| FixedPoint16 (double rhs)
| FixedPoint16 (const FixedPoint16 &other)
template<int IntBits2, FPOverflowHandling OverflowHandling2>
| FixedPoint16 (const FixedPoint16< IntBits2, OverflowHandling2 > &other)
| operator double () const
| operator float () const
template<int IntBits2>
FixedPoint16 & | operator*= (const FixedPoint16< IntBits2, OverflowHandling > &other)
FixedPoint16 | operator+ () const
FixedPoint16 & | operator++ ()
FixedPoint16 | operator++ (int)
template<int IntBits2>
FixedPoint16 & | operator+= (const FixedPoint16< IntBits2, OverflowHandling > &other)
FixedPoint16 | operator- () const
FixedPoint16 & | operator-- ()
FixedPoint16 | operator-- (int)
template<int IntBits2>
FixedPoint16 & | operator-= (const FixedPoint16< IntBits2, OverflowHandling > &other)
template<int IntBits2>
FixedPoint16 & | operator/= (const FixedPoint16< IntBits2, OverflowHandling > &other)
FixedPoint16 & | operator= (Int32 rhs)
FixedPoint16 & | operator= (double rhs)
FixedPoint16 & | operator= (const FixedPoint16 &other)
template<int IntBits2>
FixedPoint16 & | operator= (const FixedPoint16< IntBits2, OverflowHandling > &other)

## Detailed Description

### template<int IntBits, FPOverflowHandling OverflowHandling = FPOverflowIgnore>
class vigra::FixedPoint16< IntBits, OverflowHandling >

Template for 16-bit signed 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 `Int16` and uses `IntBits` to represent the integral part of a number, and `15 - IntBits` for the fractional part. The 16th bit is reserved because FixedPoint16 is a signed type. Results of expressions with mixed types will preserve larger number of `IntBits` of the results, in order to minimize the possibility for overflow. Nonetheless, overflow can occur, and the template parameter `OverflowHandling` determines how this will be handled:

FPOverflowIgnore

  (default) Ignore overflow, i.e. use the usual modulo behavior of the built-in integer types.

FPOverflowSaturate

  Use the largest or smallest representable number (depending on sign) in case of overflow.

FPOverflowError
  Throw `PreconditionViolation` upon overflow. This is useful for debugging.

The implementation relies on Int32-arithmetic and requires that the right-shift operator preserves signedness. Although not enforced by the C++ standard, this is implemented by most of today's processors. This property is checked by a VIGRA_STATIC_ASSERT(FixedPoint_error__Right_shift_operator_has_unsupported_semantics).

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

Built-in numeric types can be converted into `FixedPoint16` by the appropriate constructors, and from `FixedPoint16` by means of `fixed_point_cast<TargetType>(fixedPoint)`.

See also:

- Functions for FixedPoint16
- Numeric and Promote Traits of FixedPoint16

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

## Constructor & Destructor Documentation

FixedPoint16 | ( | Int32 | v | ) |
| explicit

Construct from an int (fractional part will become zero). Possible overflow is handled according to the target type's `OverflowHandling`.

FixedPoint16 | ( | Int32 | v,
|  | FixedPointNoShift |
| ) |  |

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

FixedPoint16 | ( | double | rhs | ) |
| explicit

Construct from a double and round the fractional part to `FRACTIONAL_BITS` accuracy. Possible overflow is handled according to the target type's `OverflowHandling`.

FixedPoint16 | ( | const FixedPoint16< IntBits, OverflowHandling > & | other | ) |

Copy constructor.

FixedPoint16 | ( | const FixedPoint16< IntBits2, OverflowHandling2 > & | other | ) |

Construct from a FixedPoint16 with different layout. It rounds as appropriate and handles possible overflow according to the target type's `OverflowHandling`.

## Member Function Documentation

FixedPoint16& operator= | ( | Int32 | rhs | ) |

Assignment from int. The fractional part will become zero. Possible overflow is handled according to the target type's `OverflowHandling`.

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

Assignment form double. The fractional part is rounded, and possible overflow is handled according to the target type's `OverflowHandling`.

FixedPoint16& operator= | ( | const FixedPoint16< IntBits, OverflowHandling > & | other | ) |

Copy assignment.

FixedPoint16& operator= | ( | const FixedPoint16< IntBits2, OverflowHandling > & | other | ) |

Assignment from a FixedPoint16 with different layout. It rounds as appropriate, and possible overflow is handled according to the target type's `OverflowHandling`.

operator float | ( |  | ) | const

Conversion to float

operator double | ( |  | ) | const

Conversion to double

FixedPoint16 operator+ | ( |  | ) | const

Unary plus.

FixedPoint16 operator- | ( |  | ) | const

Negation.

FixedPoint16& operator++ | ( |  | ) |

Pre-increment.

FixedPoint16 operator++ | ( | int |  | ) |

Post-increment.

FixedPoint16& operator-- | ( |  | ) |

Pre-decrement.

FixedPoint16 operator-- | ( | int |  | ) |

Post-decrement.

FixedPoint16& operator+= | ( | const FixedPoint16< IntBits2, OverflowHandling > & | other | ) |

Add-assignment from a FixedPoint16 with different layout. It rounds as appropriate, and possible overflow is handled according to the target type's `OverflowHandling`.

FixedPoint16& operator-= | ( | const FixedPoint16< IntBits2, OverflowHandling > & | other | ) |

Subtract-assignment from a FixedPoint16 with different layout. It rounds as appropriate, and possible overflow is handled according to the target type's `OverflowHandling`.

FixedPoint16& operator*= | ( | const FixedPoint16< IntBits2, OverflowHandling > & | other | ) |

Multiply-assignment from a FixedPoint16 with different layout. It rounds as appropriate, and possible overflow is handled according to the target type's `OverflowHandling`.

FixedPoint16& operator/= | ( | const FixedPoint16< IntBits2, OverflowHandling > & | other | ) |

Divide-assignment from a FixedPoint16 with different layout. It rounds as appropriate, and possible overflow is handled according to the target type's `OverflowHandling`.

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.11.1 (Fri May 19 2017)