2020-09-30 17:12:29 +02:00

117 lines
3.7 KiB
Plaintext

// numeric standard header
#ifndef _NUMERIC_
#define _NUMERIC_
#include <use_ansi.h>
#include <xstddef>
#ifdef _MSC_VER
/*
* Currently, all MS C compilers for Win32 platforms default to 8 byte
* alignment.
*/
#pragma pack(push,8)
#endif /* _MSC_VER */
// TEMPLATE FUNCTION accumulate
template<class _II, class _TYPE> inline
_TYPE accumulate(_II _F, _II _L, _TYPE _V)
{for (; _F != _L; ++_F)
_V = _V + *_F;
return (_V); }
// TEMPLATE FUNCTION accumulate WITH BINOP
template<class _II, class _TYPE, class _Bop> inline
_TYPE accumulate(_II _F, _II _L, _TYPE _V, _Bop _B)
{for (; _F != _L; ++_F)
_V = _B(_V, *_F);
return (_V); }
// TEMPLATE FUNCTION inner_product
template<class _II1, class _II2, class _TYPE> inline
_TYPE inner_product(_II1 _F, _II1 _L, _II2 _X, _TYPE _V)
{for (; _F != _L; ++_F, ++_X)
_V = _V + *_F * *_X;
return (_V); }
// TEMPLATE FUNCTION inner_product WITH BINOPS
template<class _II1, class _II2, class _TYPE,
class _Bop1, class _Bop2> inline
_TYPE inner_product(_II1 _F, _II1 _L, _II2 _X, _TYPE _V,
_Bop1 _B1, _Bop2 _B2)
{for (; _F != _L; ++_F, ++_X)
_V = _B1(_V, _B2(*_F, *_X));
return (_V); }
// TEMPLATE FUNCTION partial_sum
template<class _II, class _OI> inline
_OI partial_sum(_II _F, _II _L, _OI _X)
{return (_F == _L ? _X
: _Partial_sum(_F, _L, _X, _Val_type(_F))); }
template<class _II, class _OI, class _TYPE> inline
_OI _Partial_sum(_II _F, _II _L, _OI _X, _TYPE *)
{_TYPE _V = *_F;
for (*_X = _V; ++_F != _L; *++_X = _V)
_V = _V + *_F;
return (++_X); }
// TEMPLATE FUNCTION partial_sum WITH BINOP
template<class _II, class _OI, class _Bop> inline
_OI partial_sum(_II _F, _II _L, _OI _X, _Bop _B)
{return (_F == _L ? _X
: _Partial_sum(_F, _L, _X, _B, _Val_type(_F))); }
template<class _II, class _OI, class _Bop, class _TYPE> inline
_OI _Partial_sum(_II _F, _II _L, _OI _X, _Bop _B, _TYPE *)
{_TYPE _V = *_F;
for (*_X = _V; ++_F != _L; *++_X = _V)
_V = _B(_V, *_F);
return (++_X); }
// TEMPLATE FUNCTION adjacent_difference
template<class _II, class _OI> inline
_OI adjacent_difference(_II _F, _II _L, _OI _X)
{return (_F == _L ? _X
: _Adjacent_difference(_F, _L, _X, _Val_type(_F))); }
template<class _II, class _OI, class _TYPE> inline
_OI _Adjacent_difference(_II _F, _II _L, _OI _X, _TYPE *)
{_TYPE _V = *_F;
for (*_X = _V; ++_F != _L; )
{_TYPE _Tmp = *_F;
*++_X = _Tmp - _V;
_V = _Tmp; }
return (++_X); }
// TEMPLATE FUNCTION adjacent_difference WITH BINOP
template<class _II, class _OI, class _Bop> inline
_OI adjacent_difference(_II _F, _II _L, _OI _X, _Bop _B)
{return (_F == _L ? _X
: _Adjacent_difference(_F, _L, _X, _B, _Val_type(_F))); }
template<class _II, class _OI, class _Bop, class _TYPE> inline
_OI _Adjacent_difference(_II _F, _II _L, _OI _X, _Bop _B, _TYPE *)
{_TYPE _V = *_F;
for (*_X = _V; ++_F != _L; )
{_TYPE _Tmp = *_F;
*++_X = _B(_Tmp, _V);
_V = _Tmp; }
return (++_X); }
#ifdef _MSC_VER
#pragma pack(pop)
#endif /* _MSC_VER */
#endif /* _NUMERIC_ */
/*
* Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
* Consult your license regarding permissions and restrictions.
*/
/*
* This file is derived from software bearing the following
* restrictions:
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this
* software and its documentation for any purpose is hereby
* granted without fee, provided that the above copyright notice
* appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation.
* Hewlett-Packard Company makes no representations about the
* suitability of this software for any purpose. It is provided
* "as is" without express or implied warranty.
*/