ReactOS 0.4.16-dev-109-gf4cb10f
_numeric.c
Go to the documentation of this file.
1/*
2 *
3 *
4 * Copyright (c) 1994
5 * Hewlett-Packard Company
6 *
7 * Copyright (c) 1996,1997
8 * Silicon Graphics Computer Systems, Inc.
9 *
10 * Copyright (c) 1997
11 * Moscow Center for SPARC Technology
12 *
13 * Copyright (c) 1999
14 * Boris Fomitchev
15 *
16 * This material is provided "as is", with absolutely no warranty expressed
17 * or implied. Any use is at your own risk.
18 *
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.
24 *
25 */
26#ifndef _STLP_NUMERIC_C
27#define _STLP_NUMERIC_C
28
29#ifndef _STLP_INTERNAL_NUMERIC_H
30# include <stl/_numeric.h>
31#endif
32
34
36
37template <class _InputIterator, class _OutputIterator, class _Tp,
38 class _BinaryOperation>
39_OutputIterator
40__partial_sum(_InputIterator __first, _InputIterator __last,
41 _OutputIterator __result, _Tp*, _BinaryOperation __binary_op) {
42 _STLP_DEBUG_CHECK(__check_range(__first, __last))
43 if (__first == __last) return __result;
44 *__result = *__first;
45
46 _Tp __val = *__first;
47 while (++__first != __last) {
48 __val = __binary_op(__val, *__first);
49 *++__result = __val;
50 }
51 return ++__result;
52}
53
54template <class _InputIterator, class _OutputIterator, class _Tp,
55 class _BinaryOperation>
56_OutputIterator
57__adjacent_difference(_InputIterator __first, _InputIterator __last,
58 _OutputIterator __result, _Tp*,
59 _BinaryOperation __binary_op) {
60 _STLP_DEBUG_CHECK(__check_range(__first, __last))
61 if (__first == __last) return __result;
62 *__result = *__first;
63 _Tp __val = *__first;
64 while (++__first != __last) {
65 _Tp __tmp = *__first;
66 *++__result = __binary_op(__tmp, __val);
67 __val = __tmp;
68 }
69 return ++__result;
70}
71
72
73template <class _Tp, class _Integer, class _MonoidOperation>
74_Tp __power(_Tp __x, _Integer __n, _MonoidOperation __opr) {
76 if (__n == 0)
77 return __identity_element(__opr);
78 else {
79 while ((__n & 1) == 0) {
80 __n >>= 1;
81 __x = __opr(__x, __x);
82 }
83 _Tp __result = __x;
85 __n >>= 1;
86 while (__n != 0) {
87 __x = __opr(__x, __x);
88 if ((__n & 1) != 0)
89 __result = __opr(__result, __x);
90 __n >>= 1;
91 }
92 return __result;
94 }
95 _STLP_MPWFIX_CATCH_ACTION(__x = _Tp())
96}
97
99
101
102#endif /* _STLP_NUMERIC_C */
103
104// Local Variables:
105// mode:C++
106// End:
_STLP_INLINE_LOOP _InputIter __last
Definition: _algo.h:68
return __n
Definition: _algo.h:75
_STLP_INLINE_LOOP _InputIter const _Tp & __val
Definition: _algobase.h:656
#define _STLP_MPWFIX_CATCH
Definition: _apple.h:111
#define _STLP_MPWFIX_CATCH_ACTION(action)
Definition: _apple.h:112
#define _STLP_MPWFIX_TRY
Definition: _apple.h:110
#define _STLP_DEBUG_CHECK(expr)
Definition: _debug.h:440
_Tp __identity_element(plus< _Tp >)
_Tp __power(_Tp __x, _Integer __n, _MonoidOperation __opr)
Definition: _numeric.c:74
_OutputIterator __adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp *, _BinaryOperation __binary_op)
Definition: _numeric.c:57
_STLP_BEGIN_NAMESPACE _STLP_MOVE_TO_PRIV_NAMESPACE _OutputIterator __partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp *, _BinaryOperation __binary_op)
Definition: _numeric.c:40
#define _STLP_MOVE_TO_STD_NAMESPACE
Definition: features.h:525
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
#define _STLP_END_NAMESPACE
Definition: features.h:503
#define _STLP_MOVE_TO_PRIV_NAMESPACE
Definition: features.h:524