Arduino Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
error_module.hpp
Go to the documentation of this file.
1 // Author: Mario S. Könz <mskoenz@gmx.net>
2 // Date: 20.07.2013 11:27:09 EDT
3 // File: error_module.hpp
4 
5 /* This program is free software. It comes without any warranty, to
6  * the extent permitted by applicable law. You can redistribute it
7  * and/or modify it under the terms of the Do What The Fuck You Want
8  * To Public License, Version 2, as published by Sam Hocevar. See
9  * http://www.wtfpl.net/ or COPYING for more details. */
10 
11 #ifndef __ERROR_MODULE_HEADER
12 #define __ERROR_MODULE_HEADER
13 
14 #ifndef Arduino_h
15  #include <cmath>
16 #endif
17 
18 #include "module.hpp"
19 
20 namespace ustd {
21  namespace detail {
22  template<>
23  struct requirement<tag::error> {
25  };
26  }//end namespace detail
27 
28  template<typename T, typename _base>
29  class module<T, tag::error, _base>: public _base {
30  typedef _base base;
31  typedef typename util::mean_trait<T>::type error_type;
32  public:
33  //------------------- ctor -------------------
34  module(): base(), sum2_(0) {
35  }
36  //------------------- ops -------------------
37  void operator<<(T const & in) {
38  base::operator<<(in);
39  sum2_ += error_type(in) * in;
40  }//------------------- fct -------------------
41  error_type std() const {
42  //~ using std::sqrt;
43  return sqrt((sum2_ - base::mean() * base::mean() * base::count()) / (base::count() - 1));
44  }
45  error_type m_std() const {
46  //~ using std::sqrt;
47  return std() / sqrt(base::count());
48  }
49  void clear() {
50  base::clear();
51  sum2_ = error_type();
52  }
53  private:
54  error_type sum2_;
55  };
56 }//end namespace ustd
57 
58 #endif //__ERROR_MODULE_HEADER
S & operator<<(S &os, oss_class< D, max_buf > const &arg)
Definition: serializer.hpp:158
Definition: module.hpp:33
ustd::conditional< detail::use_double_identifier< T >::value, double, T >::type type
Definition: mean_trait.hpp:44
module()
Definition: error_module.hpp:34
Definition: meta_list.hpp:17
error_type std() const
Definition: error_module.hpp:41
void clear()
Definition: error_module.hpp:49
error_type m_std() const
Definition: error_module.hpp:45
void operator<<(T const &in)
Definition: error_module.hpp:37