- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Executives/DeductiveController/Configs/TI_DSP_BIOS/stl/stl_numeric.h

    00001 /*
    00002  *
    00003  * Copyright (c) 1994
    00004  * Hewlett-Packard Company
    00005  *
    00006  * Permission to use, copy, modify, distribute and sell this software
    00007  * and its documentation for any purpose is hereby granted without fee,
    00008  * provided that the above copyright notice appear in all copies and
    00009  * that both that copyright notice and this permission notice appear
    00010  * in supporting documentation.  Hewlett-Packard Company makes no
    00011  * representations about the suitability of this software for any
    00012  * purpose.  It is provided "as is" without express or implied warranty.
    00013  *
    00014  *
    00015  * Copyright (c) 1996,1997
    00016  * Silicon Graphics Computer Systems, Inc.
    00017  *
    00018  * Permission to use, copy, modify, distribute and sell this software
    00019  * and its documentation for any purpose is hereby granted without fee,
    00020  * provided that the above copyright notice appear in all copies and
    00021  * that both that copyright notice and this permission notice appear
    00022  * in supporting documentation.  Silicon Graphics makes no
    00023  * representations about the suitability of this software for any
    00024  * purpose.  It is provided "as is" without express or implied warranty.
    00025  */
    00026
    00027 /* NOTE: This is an internal header file, included by other STL headers.
    00028  *   You should not attempt to use it directly.
    00029  */
    00030
    00031
    00032 #ifndef __SGI_STL_INTERNAL_NUMERIC_H
    00033 #define __SGI_STL_INTERNAL_NUMERIC_H
    00034
    00035 __STL_BEGIN_NAMESPACE
    00036
    00037 template <class _InputIterator, class _Tp>
    00038 _Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
    00039 {
    00040   for ( ; __first != __last; ++__first)
    00041     __init = __init + *__first;
    00042   return __init;
    00043 }
    00044
    00045 template <class _InputIterator, class _Tp, class _BinaryOperation>
    00046 _Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init,
    00047                _BinaryOperation __binary_op)
    00048 {
    00049   for ( ; __first != __last; ++__first)
    00050     __init = __binary_op(__init, *__first);
    00051   return __init;
    00052 }
    00053
    00054 template <class _InputIterator1, class _InputIterator2, class _Tp>
    00055 _Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
    00056                   _InputIterator2 __first2, _Tp __init)
    00057 {
    00058   for ( ; __first1 != __last1; ++__first1, ++__first2)
    00059     __init = __init + (*__first1 * *__first2);
    00060   return __init;
    00061 }
    00062
    00063 template <class _InputIterator1, class _InputIterator2, class _Tp,
    00064           class _BinaryOperation1, class _BinaryOperation2>
    00065 _Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
    00066                   _InputIterator2 __first2, _Tp __init,
    00067                   _BinaryOperation1 __binary_op1,
    00068                   _BinaryOperation2 __binary_op2)
    00069 {
    00070   for ( ; __first1 != __last1; ++__first1, ++__first2)
    00071     __init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
    00072   return __init;
    00073 }
    00074
    00075 template <class _InputIterator, class _OutputIterator, class _Tp>
    00076 _OutputIterator
    00077 __partial_sum(_InputIterator __first, _InputIterator __last,
    00078               _OutputIterator __result, _Tp*)
    00079 {
    00080   _Tp __value = *__first;
    00081   while (++__first != __last) {
    00082     __value = __value + *__first;
    00083     *++__result = __value;
    00084   }
    00085   return ++__result;
    00086 }
    00087
    00088 template <class _InputIterator, class _OutputIterator>
    00089 _OutputIterator
    00090 partial_sum(_InputIterator __first, _InputIterator __last,
    00091             _OutputIterator __result)
    00092 {
    00093   if (__first == __last) return __result;
    00094   *__result = *__first;
    00095   return __partial_sum(__first, __last, __result, __VALUE_TYPE(__first));
    00096 }
    00097
    00098 template <class _InputIterator, class _OutputIterator, class _Tp,
    00099           class _BinaryOperation>
    00100 _OutputIterator
    00101 __partial_sum(_InputIterator __first, _InputIterator __last,
    00102               _OutputIterator __result, _Tp*, _BinaryOperation __binary_op)
    00103 {
    00104   _Tp __value = *__first;
    00105   while (++__first != __last) {
    00106     __value = __binary_op(__value, *__first);
    00107     *++__result = __value;
    00108   }
    00109   return ++__result;
    00110 }
    00111
    00112 template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
    00113 _OutputIterator
    00114 partial_sum(_InputIterator __first, _InputIterator __last,
    00115             _OutputIterator __result, _BinaryOperation __binary_op)
    00116 {
    00117   if (__first == __last) return __result;
    00118   *__result = *__first;
    00119   return __partial_sum(__first, __last, __result, __VALUE_TYPE(__first),
    00120                        __binary_op);
    00121 }
    00122
    00123 template <class _InputIterator, class _OutputIterator, class _Tp>
    00124 _OutputIterator
    00125 __adjacent_difference(_InputIterator __first, _InputIterator __last,
    00126                       _OutputIterator __result, _Tp*)
    00127 {
    00128   _Tp __value = *__first;
    00129   while (++__first != __last) {
    00130     _Tp __tmp = *__first;
    00131     *++__result = __tmp - __value;
    00132     __value = __tmp;
    00133   }
    00134   return ++__result;
    00135 }
    00136
    00137 template <class _InputIterator, class _OutputIterator>
    00138 _OutputIterator
    00139 adjacent_difference(_InputIterator __first,
    00140                     _InputIterator __last, _OutputIterator __result)
    00141 {
    00142   if (__first == __last) return __result;
    00143   *__result = *__first;
    00144   return __adjacent_difference(__first, __last, __result,
    00145                                __VALUE_TYPE(__first));
    00146 }
    00147
    00148 template <class _InputIterator, class _OutputIterator, class _Tp,
    00149           class _BinaryOperation>
    00150 _OutputIterator
    00151 __adjacent_difference(_InputIterator __first, _InputIterator __last,
    00152                       _OutputIterator __result, _Tp*,
    00153                       _BinaryOperation __binary_op) {
    00154   _Tp __value = *__first;
    00155   while (++__first != __last) {
    00156     _Tp __tmp = *__first;
    00157     *++__result = __binary_op(__tmp, __value);
    00158     __value = __tmp;
    00159   }
    00160   return ++__result;
    00161 }
    00162
    00163 template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
    00164 _OutputIterator
    00165 adjacent_difference(_InputIterator __first, _InputIterator __last,
    00166                     _OutputIterator __result, _BinaryOperation __binary_op)
    00167 {
    00168   if (__first == __last) return __result;
    00169   *__result = *__first;
    00170   return __adjacent_difference(__first, __last, __result,
    00171                                __VALUE_TYPE(__first),
    00172                                __binary_op);
    00173 }
    00174
    00175 // Returns __x ** __n, where __n >= 0.  _Note that "multiplication"
    00176 // is required to be associative, but not necessarily commutative.
    00177
    00178
    00179 template <class _Tp, class _Integer, class _MonoidOperation>
    00180 _Tp __power(_Tp __x, _Integer __n, _MonoidOperation __oper)
    00181 {
    00182   if (__n == 0)
    00183     return identity_element(__oper);
    00184   else {
    00185     while ((__n & 1) == 0) {
    00186       __n >>= 1;
    00187       __x = __oper(__x, __x);
    00188     }
    00189
    00190     _Tp __result = __x;
    00191     __n >>= 1;
    00192     while (__n != 0) {
    00193       __x = __oper(__x, __x);
    00194       if ((__n & 1) != 0)
    00195         __result = __oper(__result, __x);
    00196       __n >>= 1;
    00197     }
    00198     return __result;
    00199   }
    00200 }
    00201
    00202 template <class _Tp, class _Integer>
    00203 inline _Tp __power(_Tp __x, _Integer __n)
    00204 {
    00205   return __power(__x, __n, multiplies<_Tp>());
    00206 }
    00207
    00208 // Alias for the internal name __power.  Note that power is an extension,
    00209 // not part of the C++ standard.
    00210
    00211 template <class _Tp, class _Integer, class _MonoidOperation>
    00212 inline _Tp power(_Tp __x, _Integer __n, _MonoidOperation __oper)
    00213 {
    00214   return __power(__x, __n, __oper);
    00215 }
    00216
    00217 template <class _Tp, class _Integer>
    00218 inline _Tp power(_Tp __x, _Integer __n)
    00219 {
    00220   return __power(__x, __n);
    00221 }
    00222
    00223 // iota is not part of the C++ standard.  It is an extension.
    00224
    00225 template <class _ForwardIterator, class _Tp>
    00226 void
    00227 iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
    00228 {
    00229   while (__first != __last)
    00230     *__first++ = __value++;
    00231 }
    00232
    00233 __STL_END_NAMESPACE
    00234
    00235 #endif /* __SGI_STL_INTERNAL_NUMERIC_H */
    00236
    00237 // Local Variables:
    00238 // mode:C++
    00239 // End: