$extrastylesheet
Olena
User documentation 2.1
An Image Processing Platform
Milena
Getting started
API Reference Manual
All Classes
Examples
Demos
Publications
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
root.hh
1
// Copyright (C) 2007, 2008, 2009, 2013 EPITA Research and Development
2
// Laboratory (LRDE)
3
//
4
// This file is part of Olena.
5
//
6
// Olena is free software: you can redistribute it and/or modify it under
7
// the terms of the GNU General Public License as published by the Free
8
// Software Foundation, version 2 of the License.
9
//
10
// Olena is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
// General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with Olena. If not, see <http://www.gnu.org/licenses/>.
17
//
18
// As a special exception, you may use this file as part of a free
19
// software project without restriction. Specifically, if other files
20
// instantiate templates or use macros or inline functions from this
21
// file, or you compile this file and link it with other files to produce
22
// an executable, this file does not by itself cause the resulting
23
// executable to be covered by the GNU General Public License. This
24
// exception does not however invalidate any other reasons why the
25
// executable file might be covered by the GNU General Public License.
26
27
#ifndef MLN_METAL_MATH_ROOT_HH
28
# define MLN_METAL_MATH_ROOT_HH
29
37
# include <mln/metal/math/pow.hh>
38
39
40
# define mlc_root(N,X) mln::metal::math::root<( N ),( X )>
41
42
43
namespace
mln
44
{
45
46
namespace
metal
47
{
48
49
namespace
math
50
{
51
52
namespace
impl
53
{
54
55
template
<
unsigned
n,
unsigned
x,
56
unsigned
lo = 1,
unsigned
hi = x>
57
struct
root
58
{
59
enum
{
60
mid = (lo + hi + 1) / 2,
61
val_lo =
root<n, x, lo, mid-1>::value
,
62
val_hi =
root<n, x, mid, hi>::value
63
};
64
enum
{
value
= x <
unsigned
(mlc_pow_int(mid, n)) ? val_lo : val_hi };
65
};
66
67
template
<
unsigned
n,
unsigned
x,
unsigned
m>
68
struct
root<n, x, m, m>
69
{
70
enum
{
value
= m };
// Found.
71
};
72
73
}
// end of namespace mln::metal::math::impl
74
75
template
<
unsigned
n,
unsigned
x>
76
struct
root :
bool_
<(n != 0)>::check_t
77
{
78
enum
{
value
=
impl::root<n,x>::value
,
79
reminder = x - mlc_pow_int(
value
, n) };
80
};
81
82
template
<
unsigned
n>
83
struct
root<n, 0> :
bool_
<(n != 0)>::check_t
84
{
85
enum
{
value
= 0,
86
reminder = 0};
87
};
88
89
}
// end of namespace mln::metal::math
90
91
}
// end of namespace mln::metal
92
93
}
// end of namespace mln
94
95
96
#endif // ! MLN_METAL_MATH_ROOT_HH
mln
metal
math
root.hh
Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)