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 _STLP_MOVE_TO_PRIV_NAMESPACE
37 template <class _InputIterator
, class _OutputIterator
, class _Tp
,
38 class _BinaryOperation
>
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
;
47 while (++__first
!= __last
) {
48 __val
= __binary_op(__val
, *__first
);
54 template <class _InputIterator
, class _OutputIterator
, class _Tp
,
55 class _BinaryOperation
>
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
;
64 while (++__first
!= __last
) {
66 *++__result
= __binary_op(__tmp
, __val
);
73 template <class _Tp
, class _Integer
, class _MonoidOperation
>
74 _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())
98 _STLP_MOVE_TO_STD_NAMESPACE
102 #endif /* _STLP_NUMERIC_C */