# MathematicalAlgorithms

BOOST WIKI | RecentChanges | Preferences | Page List | Links List

Difference (from prior major revision) (no other diffs)

Removed: 50,59d49
 [企业培训] [企业内训] [管理顾问] [人力资源] [zippo] [zippo玩法] [zippo玩法]

I have some code I'm happy to share, as I'm sure many people do. However, it's probably wait until an interface is decided upon. Once that happens, I can see how much work it would be to make some of my code fit in with the boost layout. --Eford

The following two algorithms are in STL but not in C++ Standard Library yet. However, algorithm power is very useful. -- Lie-Quan Lee

• IdentityElement?
```    template <class _Tp> inline _Tp identity_element(plus<_Tp>) {
return _Tp(0);
}
template <class _Tp> inline _Tp identity_element(multiplies<_Tp>) {
return _Tp(1);
}
```

• Power

```    template <class _Tp, class _Integer, class _MonoidOperation? >
_Tp power(_Tp __x, _Integer __n, _MonoidOperation?  __monoid_op) {
if (__n == 0)
return identity_element(__monoid_op);
else {
while ((__n & 1) == 0) {
__n >>= 1;
__x = __monoid_op(__x, __x);
}
```

```            _Tp __result = __x;
__n >>= 1;
while (__n != 0) {
__x = __monoid_op(__x, __x);
if ((__n & 1) != 0)
__result = __monoid_op(__result, __x);
__n >>= 1;
}
return __result;
}
}
```

```    template <class _Tp, class _Integer>
inline _Tp power(_Tp __x, _Integer __n) {
return power(__x, __n, multiplies<_Tp>());
}
```

I have a few variations on std::accumulate that reorder the elements first to minimize round off errors in the accumulation. However, they are obviously only useful for commutative situations. Is there any interest in them?

John Phillips

BOOST WIKI | RecentChanges | Preferences | Page List | Links List