STIR 6.4.0
divide.inl
Go to the documentation of this file.
1//
2//
3/*
4 Copyright (C) 2000 PARAPET partners
5 Copyright (C) 2000- 2007, Hammersmith Imanet Ltd
6 This file is part of STIR.
7
8 SPDX-License-Identifier: Apache-2.0 AND License-ref-PARAPET-license
9
10 See STIR/LICENSE.txt for details
11*/
22#include <cmath>
23
24START_NAMESPACE_STIR
25
26template <class NumeratorIterT, class DenominatorIterT, class small_numT>
27void
28divide(const NumeratorIterT& numerator_begin,
29 const NumeratorIterT& numerator_end,
30 const DenominatorIterT& denominator_begin,
31 const small_numT small_num)
32{
33 small_numT small_value = *std::max_element(numerator_begin, numerator_end) * small_num;
34 small_value = (small_value > 0) ? small_value : 0;
35
36 NumeratorIterT numerator_iter = numerator_begin;
37 DenominatorIterT denominator_iter = denominator_begin;
38 while (numerator_iter != numerator_end)
39 {
40 if (std::fabs(*denominator_iter) <= small_value && std::fabs(*numerator_iter) <= small_value)
41 (*numerator_iter) = 0;
42 else
43 (*numerator_iter) /= (*denominator_iter);
44 ++numerator_iter;
45 ++denominator_iter;
46 }
47}
48
49END_NAMESPACE_STIR
void divide(const NumeratorIterT &numerator_begin, const NumeratorIterT &numerator_end, const DenominatorIterT &denominator_begin, const small_numT small_num)
division of two ranges, 0/0 = 0
Definition divide.inl:28