Code-Eli  0.3.6
sign_changes.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2 * Copyright (c) 2013 David D. Marshall <ddmarsha@calpoly.edu>
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * David D. Marshall - initial code and implementation
11 ********************************************************************************/
12 
13 #ifndef eli_mutil_poly_root_sign_changes_hpp
14 #define eli_mutil_poly_root_sign_changes_hpp
15 
16 #include "eli/code_eli.hpp"
17 
18 namespace eli
19 {
20  namespace mutil
21  {
22  namespace poly
23  {
24  namespace root
25  {
26  // this counts the number of sign changes in collection (excluding zeros)
27  template<typename it__>
28  int sign_changes(const it__ itb, const it__ ite)
29  {
30  if (itb==ite)
31  return 0;
32 
33  int count(0);
34  it__ it(itb);
35  bool prev_sign=((*it)>0);
36 
37  for (++it; it!=ite; ++it)
38  {
39  if ( ((*it)!=0) && (prev_sign!=((*it)>0)) )
40  {
41  count++;
42  prev_sign=!prev_sign;
43  }
44  }
45 
46  return count;
47  }
48  }
49  }
50  }
51 }
52 
53 #endif
Definition: math.hpp:20
int sign_changes(const it__ itb, const it__ ite)
Definition: sign_changes.hpp:28