00001 #pragma once 00002 /** 00003 * \file NETGeographicLib/Accumulator.h 00004 * \brief Header for NETGeographicLib::Accumulator class 00005 * 00006 * NETGeographicLib is copyright (c) Scott Heiman (2013) 00007 * GeographicLib is Copyright (c) Charles Karney (2010-2012) 00008 * <charles@karney.com> and licensed under the MIT/X11 License. 00009 * For more information, see 00010 * http://geographiclib.sourceforge.net/ 00011 **********************************************************************/ 00012 00013 namespace NETGeographicLib 00014 { 00015 /*! 00016 \brief .NET wrapper for GeographicLib::Accumulator. 00017 00018 This class allows .NET applications to access GeographicLib::Accumulator<double>. 00019 00020 This allow many numbers of floating point type \e double to be added together 00021 with twice the normal precision. The effective 00022 precision of the sum is 106 bits or about 32 decimal places. 00023 00024 The implementation follows J. R. Shewchuk, 00025 <a href="http://dx.doi.org/10.1007/PL00009321"> Adaptive Precision 00026 Floating-Point Arithmetic and Fast Robust Geometric Predicates</a>, 00027 Discrete & Computational Geometry 18(3) 305--363 (1997). 00028 00029 C# Example: 00030 \include example-Accumulator.cs 00031 Managed C++ Example: 00032 \include example-Accumulator.cpp 00033 Visual Basic Example: 00034 \include example-Accumulator.vb 00035 00036 <B>INTERFACE DIFFERENCES:</B><BR> 00037 Since assignment operators (=,+=,-=,*=) are not supported in managed classes; 00038 - the Assign() method replaces the = operator, 00039 - the Sum() method replaces the += and -= operators, and 00040 - the Multiply() method replaces the *= operator, 00041 00042 Use Result() instead of the () operator to obtain the summed value from the accumulator. 00043 */ 00044 public ref class Accumulator 00045 { 00046 private: 00047 // Pointer to the unmanaged GeographicLib::Accumulator. 00048 GeographicLib::Accumulator<double>* m_pAccumulator; 00049 // The finalizer releases the unmanaged object when this class is destroyrd. 00050 !Accumulator(void); 00051 public: 00052 //! \brief Constructor. 00053 Accumulator(void); 00054 //! \brief Destructor calls the finalizer. 00055 ~Accumulator() { this->!Accumulator(); } 00056 /*! 00057 \brief Assigns a value to an accumulator. 00058 \param[in] a The value to be assigned. 00059 */ 00060 void Assign( double a ); 00061 //! \brief Returns the accumulated value. 00062 double Result(); 00063 /*! 00064 \brief Adds a value to the accumulator. 00065 \param[in] a The value to be added. 00066 */ 00067 void Sum( double a ); 00068 /*! 00069 \brief Multiplication by an integer 00070 \param[in] i The multiplier. 00071 */ 00072 void Multiply( int i ); 00073 /*! 00074 \brief Equality operator. 00075 \param[in] lhs The accumulator. 00076 \param[in] a The value to be compared to. 00077 \return true if the accumulated value is equal to a. 00078 */ 00079 static bool operator == ( Accumulator^ lhs, double a ); 00080 /*! 00081 \brief Inequality operator. 00082 \param[in] lhs The accumulator. 00083 \param[in] a The value to be compared to. 00084 \return true if the accumulated value is not equal to a. 00085 */ 00086 static bool operator != ( Accumulator^ lhs, double a ); 00087 /*! 00088 \brief Less than operator. 00089 \param[in] lhs The accumulator. 00090 \param[in] a The value to be compared to. 00091 \return true if the accumulated value is less than a. 00092 */ 00093 static bool operator < ( Accumulator^ lhs, double a ); 00094 /*! 00095 \brief Less than or equal to operator. 00096 \param[in] lhs The accumulator. 00097 \param[in] a The value to be compared to. 00098 \return true if the accumulated value is less than or equal to a. 00099 */ 00100 static bool operator <= ( Accumulator^ lhs, double a ); 00101 /*! 00102 \brief Greater than operator. 00103 \param[in] lhs The accumulator. 00104 \param[in] a The value to be compared to. 00105 \return true if the accumulated value is greater than a. 00106 */ 00107 static bool operator > ( Accumulator^ lhs, double a ); 00108 /*! 00109 \brief Greater than or equal to operator. 00110 \param[in] lhs The accumulator. 00111 \param[in] a The value to be compared to. 00112 \return true if the accumulated value is greater than or equal to a. 00113 */ 00114 static bool operator >= ( Accumulator^ lhs, double a ); 00115 }; 00116 } //namespace NETGeographicLib