名前空間
変種
操作

std::abs<div class="t-tr-text">(スタンダード:: valarrayは)<div class="t-tr-dropdown"><div><div><div class="t-tr-dropdown-arrow-border"></div><div class="t-tr-dropdown-arrow"></div><div class="t-tr-dropdown-h">Original:</div><div class="t-tr-dropdown-orig">(std::valarray)</div><div class="t-tr-dropdown-notes">The text has been machine-translated via [http://translate.google.com Google Translate].<br/> You can help to correct and verify the translation. Click [http://en.cppreference.com/w/Cppreference:MachineTranslations here] for instructions.</div></div></div></div></div>

提供: cppreference.com
< cpp‎ | numeric‎ | valarray

 
 
 
 
ヘッダ <valarray> で定義
template< class T >
valarray<T> abs( const valarray<T>& va );
値の配列の各要素の絶対値を計算する.
Original:
Computes absolute value of each element in the value array.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集] パラメータ

va -
に操作を適用する値の配列
Original:
value array to apply the operation to
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 値を返します

va内の値の絶対値を含む値の配列.
Original:
Value array containing absolute values of the values in va.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] ノート

修飾されていない機能(abs)計算を実行するために使用されます。そのような機能が利用できない場合、std::absは、引数依存の照合のために使用され.
Original:
Unqualified function (abs) is used to perform the computation. If such function is not available, std::abs is used due to argument dependent lookup.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
関数はstd::valarrayから別の戻り値型で実装することができます。この場合、交換型は、次のプロパティがあります
Original:
The function can be implemented with the return type different from std::valarray. In this case, the replacement type has the following properties:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 可能な実装

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

[編集]

#include <valarray>
#include <iostream>
 
int main()
{
    std::valarray<int> v{1, -2, 3, -4, 5, -6, 7, -8};
    std::valarray<int> v2 = std::abs(v);
    for(auto n : v2) {
        std::cout << n << ' ';
    }
    std::cout << '\n';
}

出力:

1 2 3 4 5 6 7 8

[編集] 参照

整数値(|x|)の絶対値を計算します
Original:
computes absolute value of an integral value (|x|)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数)
浮動小数点値の絶対値(|x|
Original:
absolute value of a floating point value (|x|)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数)
複素数の絶対値を返します
(関数テンプレート) [edit]