home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 41 / IOPROG_41.ISO / soft / c++ / NUMCPP11.ZIP / utility.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-09  |  1.9 KB  |  72 lines

  1. //===================================================================
  2. // utility.hpp
  3. //
  4. // Version 1.0
  5. //
  6. // Written by:
  7. //   Brent Worden
  8. //   WordenWare
  9. //   email:  Brent@Worden.org
  10. //
  11. // Copyright (c) 1999 WordenWare
  12. //
  13. // Created:  April 16, 1999
  14. // Revised:  
  15. //===================================================================
  16.  
  17. #ifndef _UTILITY_HPP_
  18. #define _UTILITY_HPP_
  19.  
  20. #include <iterator>
  21. #include "numerics.h"
  22.  
  23. NUM_BEGIN
  24.  
  25. template<class T>
  26. inline T absoluteValue(T value)
  27. //--------------------------------------------------------------------
  28. // Return the absolute value of value.
  29. //--------------------------------------------------------------------
  30. {
  31.     static T zero(0);
  32.     return value < zero ? -value : value;
  33. };
  34.  
  35. template<class T>
  36. inline bool areEqual(T a, T b, T tol = NUMERICS_MAX_ERROR)
  37. //--------------------------------------------------------------------
  38. // Return true if a and b are within tol of each other.  Otherwise,
  39. // return false.
  40. //--------------------------------------------------------------------
  41. {
  42.     return (b - tol <= a) && (a <= b + tol);
  43. }
  44.  
  45. template<class S, class T, class U>
  46. inline T* valueType(const std::iterator<S, T, U>& iter)
  47. //--------------------------------------------------------------------
  48. // Return the type contained by the iterator.
  49. //--------------------------------------------------------------------
  50. {
  51.     return ((T *)NULL);
  52. };
  53.  
  54. template<class T>
  55. inline T* valueType(const T* ptr)
  56. //--------------------------------------------------------------------
  57. // Return the type pointed to by the pointer.
  58. //--------------------------------------------------------------------
  59. {
  60.     return ((T *)NULL);
  61. };
  62.  
  63. NUM_END
  64.  
  65. #endif
  66.  
  67. //===================================================================
  68. // Revision History
  69. //
  70. // Version 1.0 - 04/16/1999 - New.
  71. //===================================================================
  72.