Instance Property インスタンスプロパティ

magnitude

The magnitude of this value. この値の規模。

Declaration 宣言

var magnitude: Float { get }

Discussion 解説

For any numeric value x, x.magnitude is the absolute value of x. You can use the magnitude property in operations that are simpler to implement in terms of unsigned values, such as printing the value of an integer, which is just printing a ‘-’ character in front of an absolute value. 何らかの数値xに対して、x.magnitudexの絶対値です。あなたは、magnitudeプロパティを、ずっと単純に符号なしの値に関して実装する演算において使用できます、例えば整数の値を印字することなど、それはちょっと「-」文字を絶対値の前に印字しています。


let x = -200
// x.magnitude == 200

The global abs(_:) function provides more familiar syntax when you need to find an absolute value. In addition, because abs(_:) always returns a value of the same type, even in a generic context, using the function instead of the magnitude property is encouraged. グローバルabs(_:)関数は、あなたが絶対値を見つける必要がある時により親しみやすい構文を提供します。加えて、abs(_:)は常に同じ型の値を返すことから、総称体の文脈においてさえも、この関数をmagnitudeプロパティの代わりに使うことは推奨されます。

Relationships 関係

From Protocol 由来プロトコル

See Also 参照

Finding the Sign and Magnitude 符号と規模を見つける