5 * Hewlett-Packard Company
7 * Copyright (c) 1996,1997
8 * Silicon Graphics Computer Systems, Inc.
11 * Moscow Center for SPARC Technology
16 * This material is provided "as is", with absolutely no warranty expressed
17 * or implied. Any use is at your own risk.
19 * Permission to use or copy this software for any purpose is hereby granted
20 * without fee, provided the above notices are retained on all copies.
21 * Permission to modify the code and to distribute modified code is granted,
22 * provided the above notices are retained, and a notice that the code was
23 * modified is included with the above copyright notice.
26 #ifndef _STLP_NUMERIC_C
27 #define _STLP_NUMERIC_C
29 #ifndef _STLP_INTERNAL_NUMERIC_H
30 # include <stl/_numeric.h>
35 template <class _InputIterator, class _OutputIterator, class _Tp,
36 class _BinaryOperation>
38 __partial_sum(_InputIterator __first, _InputIterator __last,
39 _OutputIterator __result, _Tp*, _BinaryOperation __binary_op)
41 _STLP_DEBUG_CHECK(__check_range(__first, __last))
42 if (__first == __last) return __result;
46 while (++__first != __last) {
47 __val = __binary_op(__val, *__first);
53 template <class _InputIterator, class _OutputIterator, class _Tp,
54 class _BinaryOperation>
56 __adjacent_difference(_InputIterator __first, _InputIterator __last,
57 _OutputIterator __result, _Tp*,
58 _BinaryOperation __binary_op) {
59 _STLP_DEBUG_CHECK(__check_range(__first, __last))
60 if (__first == __last) return __result;
63 while (++__first != __last) {
65 *++__result = __binary_op(__tmp, __val);
72 template <class _Tp, class _Integer, class _MonoidOperation>
73 _Tp __power(_Tp __x, _Integer __n, _MonoidOperation __opr)
77 return __identity_element(__opr);
79 while ((__n & 1) == 0) {
81 __x = __opr(__x, __x);
87 __x = __opr(__x, __x);
89 __result = __opr(__result, __x);
95 _STLP_MPWFIX_CATCH_ACTION(__x = _Tp())
100 #endif /* _STLP_NUMERIC_C */