[#mp_units-quantity-01-magnitude]
= xref:mp_units.adoc[mp&lowbar;units]::xref:mp_units/quantity-01.adoc[quantity]::magnitude
:relfileprefix: ../../
:mrdocs:

Computes the Euclidean (or, for a complex field, Hermitian) norm of a vector or tensor quantity&period;

== Synopsis

Declared in `&lt;mp&hyphen;units&sol;framework&sol;quantity&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
&lsqb;&lsqb;nodiscard&rsqb;&rsqb;
constexpr
xref:mp_units/Quantity-0c.adoc[Quantity] auto
magnitude() const
requires (get&lowbar;character(quantity&lowbar;spec)&period;order &gt;&equals; quantity&lowbar;tensor&lowbar;order&colon;&colon;vector) &amp;&amp; detail&colon;&colon;HasMagnitude&lt;rep&gt;;
----

== Description

The two&hyphen;part constraint is deliberate&colon; `order &gt;&equals; vector` is the character guard (a scalar such as `isq&colon;&colon;speed` has no magnitude, though the `magnitude` CPO would gladly run `std&colon;&colon;abs` on its `double`), and `HasMagnitude&lt;rep&gt;` ensures the storage can deliver one&period;

Returning `&ast; unit` drops the precise `quantity&lowbar;spec` to the unit&apos;s kind&colon; a V2 convenience, since V2 cannot name the right result type (a scalar&hyphen;magnitude spec like `vec&lowbar;mag&lt;isq&colon;&colon;force&gt;&lsqb;N&rsqb;` is a V3 feature)&period; This does not fix the character in general &hyphen; it collapses to `real&lowbar;scalar` only for units built from scalar base units (e&period;g&period; `km&sol;h`)&semi; for one tied to a vector spec (e&period;g&period; `N`) the result keeps `vector` character, so one could even take the magnitude of a magnitude&period; A known V2 limitation&period;

== Return Value

The norm of the numerical value, as a scalar quantity in the same unit&period;

[NOTE]
====
The return value https://en.cppreference.com/cpp/language/attributes/nodiscard[should not be discarded^].
====

[.small]#Created with https://www.mrdocs.com[MrDocs]#
