williamr@2: /* williamr@2: * williamr@2: * williamr@2: * Copyright (c) 1994 williamr@2: * Hewlett-Packard Company williamr@2: * williamr@2: * Copyright (c) 1996,1997 williamr@2: * Silicon Graphics Computer Systems, Inc. williamr@2: * williamr@2: * Copyright (c) 1997 williamr@2: * Moscow Center for SPARC Technology williamr@2: * williamr@2: * Copyright (c) 1999 williamr@2: * Boris Fomitchev williamr@2: * williamr@2: * This material is provided "as is", with absolutely no warranty expressed williamr@2: * or implied. Any use is at your own risk. williamr@2: * williamr@2: * Permission to use or copy this software for any purpose is hereby granted williamr@2: * without fee, provided the above notices are retained on all copies. williamr@2: * Permission to modify the code and to distribute modified code is granted, williamr@2: * provided the above notices are retained, and a notice that the code was williamr@2: * modified is included with the above copyright notice. williamr@2: * williamr@2: */ williamr@2: #ifndef _STLP_NUMERIC_C williamr@2: #define _STLP_NUMERIC_C williamr@2: williamr@2: #ifndef _STLP_INTERNAL_NUMERIC_H williamr@2: # include williamr@2: #endif williamr@2: williamr@2: _STLP_BEGIN_NAMESPACE williamr@2: williamr@2: template williamr@2: _OutputIterator williamr@2: __partial_sum(_InputIterator __first, _InputIterator __last, williamr@2: _OutputIterator __result, _Tp*, _BinaryOperation __binary_op) williamr@2: { williamr@2: _STLP_DEBUG_CHECK(__check_range(__first, __last)) williamr@2: if (__first == __last) return __result; williamr@2: *__result = *__first; williamr@2: williamr@2: _Tp __val = *__first; williamr@2: while (++__first != __last) { williamr@2: __val = __binary_op(__val, *__first); williamr@2: *++__result = __val; williamr@2: } williamr@2: return ++__result; williamr@2: } williamr@2: williamr@2: template williamr@2: _OutputIterator williamr@2: __adjacent_difference(_InputIterator __first, _InputIterator __last, williamr@2: _OutputIterator __result, _Tp*, williamr@2: _BinaryOperation __binary_op) { williamr@2: _STLP_DEBUG_CHECK(__check_range(__first, __last)) williamr@2: if (__first == __last) return __result; williamr@2: *__result = *__first; williamr@2: _Tp __val = *__first; williamr@2: while (++__first != __last) { williamr@2: _Tp __tmp = *__first; williamr@2: *++__result = __binary_op(__tmp, __val); williamr@2: __val = __tmp; williamr@2: } williamr@2: return ++__result; williamr@2: } williamr@2: williamr@2: williamr@2: template williamr@2: _Tp __power(_Tp __x, _Integer __n, _MonoidOperation __opr) williamr@2: { williamr@2: _STLP_MPWFIX_TRY williamr@2: if (__n == 0) williamr@2: return __identity_element(__opr); williamr@2: else { williamr@2: while ((__n & 1) == 0) { williamr@2: __n >>= 1; williamr@2: __x = __opr(__x, __x); williamr@2: } williamr@2: _Tp __result = __x; williamr@2: _STLP_MPWFIX_TRY williamr@2: __n >>= 1; williamr@2: while (__n != 0) { williamr@2: __x = __opr(__x, __x); williamr@2: if ((__n & 1) != 0) williamr@2: __result = __opr(__result, __x); williamr@2: __n >>= 1; williamr@2: } williamr@2: return __result; williamr@2: _STLP_MPWFIX_CATCH williamr@2: } williamr@2: _STLP_MPWFIX_CATCH_ACTION(__x = _Tp()) williamr@2: } williamr@2: williamr@2: _STLP_END_NAMESPACE williamr@2: williamr@2: #endif /* _STLP_NUMERIC_C */ williamr@2: williamr@2: // Local Variables: williamr@2: // mode:C++ williamr@2: // End: