numericb:C++標準程式庫中的一個b:头文件,定义了C++ STL标准中的基础性的数值算法(均为函数模板)。[1]

accumulate 编辑

  • accumulate(inIterBegin, inIterEnd, val),以val为初值,对迭代器给出的值序列做累加,返回累加结果值。值类型必须支持+(加法)算符。
  • accumulate(inIterBegin, inIterEnd, val, binFunc)为重载形式,其中binFunc为二元函数。对迭代器给出的每个值对象containerVal,执行val=binFunc(val,containerVal),返回计算结果。例如,可用于计算累乘。

adjacent_difference 编辑

  • adjacent_difference(inIterBegin, inIterEnd, outIterBegin),对输入序列,计算相邻两项的差值,写入到输出序列中。
  • adjacent_difference(inIterBegin, inIterEnd, outIterBegin, binFunc)重载形式。把减法运算符换为执行binFunc二元函数。

exclusive_scan 编辑

similar to std::partial_sum, excludes the ith input element from the ith sum

iota 编辑

  • iota (ForwardIterator first, ForwardIterator last, T val),向序列中写入以val为初值的连续值序列。

示例程序:

// iota example
#include <iostream>     // std::cout
#include <numeric>      // std::iota
#include <iterator>
#include <vector>

int main () {
  std::vector<int> numbers(10);

  std::iota (numbers.begin(),numbers.end(),100);

  std::copy( numbers.begin(), numbers.end(), std::ostream_iterator<int>(std::cout, " "));

  return 0;
}

gcd 编辑

constexpr函数模板,返回两个整数的最大公约数

inclusive_scan 编辑

similar to std::partial_sum, includes the ith input element in the ith sum

inner_product 编辑

  • inner_product(inIter1Begin, inIter1End, inIter2Begin, val),计算两个输入序列的b:内积
  • inner_product(inIter1Begin, inIter1End, inIter2Begin, val, binFunc1, binFunc2)重载形式。把上述的加法操作换为执行binFunc二元函数。

lcm 编辑

constexpr函数模板,返回两个整数的最小公倍数

partial_sum 编辑

  • partial_sum(inIterBegin, inIterEnd, outIterBegin),计算输入序列从开始位置到当前第i个位置的累加值,写入输出序列第i个位置。
  • partial_sum(inIterBegin, inIterEnd, outIterBegin, binFunc)重载形式,把上述的加法操作换为执行binFunc二元函数。

reduce 编辑

similar to std::accumulate, except out of order

transform_reduce 编辑

applies a functor, then reduces out of order

transform_inclusive_scan 编辑

applies a functor, then calculates inclusive scan

transform_exclusive_scan 编辑

applies a functor, then calculates exclusive scan


参考文献 编辑

  1. numeric头文件说明