std::log10(std::valarray)
來自 cppreference.com
定義於標頭檔案 <valarray> |
||
template< class T > valarray<T> log10( const valarray<T>& va ); |
||
對於 va 中的每個元素,計算該元素值的常用(以 10 為底)對數。
目錄 |
[編輯] 引數
va | - | 要應用操作的值陣列 |
[編輯] 返回值
包含 va 中值的常用對數的值陣列。
[編輯] 注意
使用非限定函式 (log10) 執行計算。如果此函式不可用,則由於依賴於引數的查詢,將使用 std::log10。
該函式可以使用與 std::valarray 不同的返回型別實現。在這種情況下,替換型別具有以下屬性:
- 提供 std::valarray 的所有 const 成員函式。
- std::valarray, std::slice_array, std::gslice_array, std::mask_array 和 std::indirect_array 可以從替換型別構造。
- 對於每個接受 const std::valarray<T>& 引數的函式(除了 begin() 和 end())(C++11 起),應新增接受替換型別的相同函式;
- 對於每個接受兩個 const std::valarray<T>& 引數的函式,應新增接受 const std::valarray<T>& 和替換型別的各種組合的相同函式。
- 返回型別不會在最深層巢狀的引數型別之上增加超過兩個模板巢狀級別。
[編輯] 可能的實現
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)) (函式) |
具有沿負實軸分支割線的複數常用對數 (函式模板) |