File indexing completed on 2026-08-06 09:20:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #ifndef EVT_VAL_ERROR_HH
0022 #define EVT_VAL_ERROR_HH
0023
0024 #include <assert.h>
0025 #include <iostream>
0026 #include <math.h>
0027
0028
0029
0030
0031 class EvtValError final {
0032 public:
0033 EvtValError();
0034 EvtValError( double val );
0035 EvtValError( double val, double err );
0036 EvtValError( const EvtValError& other );
0037
0038 inline int valueKnown() const { return _valKnown; }
0039 inline double value() const
0040 {
0041 assert( _valKnown );
0042 return _val;
0043 }
0044 inline int errorKnown() const { return _errKnown; }
0045 inline double error() const
0046 {
0047 assert( _errKnown );
0048 return _err;
0049 }
0050
0051 double prec() const;
0052 void operator=( const EvtValError& other );
0053 void operator*=( const EvtValError& other );
0054 void operator/=( const EvtValError& other );
0055 void operator+=( const EvtValError& other );
0056 void operator*=( double c );
0057
0058 void print( std::ostream& ) const;
0059
0060 private:
0061 int _valKnown;
0062 double _val;
0063 int _errKnown;
0064 double _err;
0065 };
0066
0067 EvtValError operator*( const EvtValError& x1, const EvtValError& x2 );
0068 EvtValError operator/( const EvtValError& x1, const EvtValError& x2 );
0069 EvtValError operator+( const EvtValError& x1, const EvtValError& x2 );
0070 EvtValError operator*( const EvtValError& x, double c );
0071 EvtValError operator*( double c, const EvtValError& x );
0072
0073 std::ostream& operator<<( std::ostream&, const EvtValError& );
0074
0075
0076
0077 template <class InputIterator, class Predicate>
0078 EvtValError accept_reject( InputIterator it, InputIterator end, Predicate pred )
0079 {
0080 int itsTried = 0;
0081 int itsPassed = 0;
0082 while ( it != end ) {
0083 itsTried++;
0084 if ( pred( *it++ ) )
0085 itsPassed++;
0086 }
0087
0088 return EvtValError( ( (double)itsPassed ) / ( (double)itsTried ),
0089 sqrt( itsPassed ) / ( (double)itsTried ) );
0090 }
0091
0092 #endif