名稱空間
變體
操作

std::log10(std::valarray)

來自 cppreference.com
< cpp‎ | 數值‎ | valarray
 
 
 
 
定義於標頭檔案 <valarray>
template< class T >
valarray<T> log10( const valarray<T>& va );

對於 va 中的每個元素,計算該元素值的常用(以 10 為底)對數。

目錄

[編輯] 引數

va - 要應用操作的值陣列

[編輯] 返回值

包含 va 中值的常用對數的值陣列。

[編輯] 注意

使用非限定函式 (log10) 執行計算。如果此函式不可用,則由於依賴於引數的查詢,將使用 std::log10

該函式可以使用與 std::valarray 不同的返回型別實現。在這種情況下,替換型別具有以下屬性:

[編輯] 可能的實現

template<class T>
valarray<T> log10(const valarray<T>& va)
{
    valarray<T> other = va;
    for (T& i : other)
        i = log10(i);
 
    return other; // proxy object may be returned
}

[編輯] 示例

#include <cmath>
#include <iomanip>
#include <iostream>
#include <valarray>
 
void show(char const* title, const std::valarray<float>& va)
{
    std::cout << title << " : " << std::right;
    for (float x : va)
        std::cout << std::setw(6) << x;
    std::cout << '\n';
}
 
int main()
{
    const std::valarray<float> n{-2.f, -1.f, 0.f, 1.f, 2.f, 3.f, INFINITY};
    const std::valarray<float> pow10{std::pow(10.f, n)};
    const std::valarray<float> log10_pow10{std::log10(pow10)};
 
    show("n      ", n);
    show("10ⁿ    ", pow10);
    show("lg(10ⁿ)", log10_pow10);
}

輸出

n       :     -2    -1     0     1     2     3   inf
10ⁿ     :   0.01   0.1     1    10   100  1000   inf
lg(10ⁿ) :     -2    -1     0     1     2     3   inf

[編輯] 參閱

將函式 std::log 應用於 valarray 的每個元素
(函式模板) [編輯]
(C++11)(C++11)
計算常用(以 10 為底)對數 (log10(x))
(函式) [編輯]
具有沿負實軸分支割線的複數常用對數
(函式模板) [編輯]