[#mp_units-quantity-01-magnitude] = xref:mp_units.adoc[mp_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. == Synopsis Declared in `<mp‐units/framework/quantity.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- [[nodiscard]] constexpr xref:mp_units/Quantity-0c.adoc[Quantity] auto magnitude() const requires (get_character(quantity_spec).order >= quantity_tensor_order::vector) && detail::HasMagnitude<rep>; ---- == Description The two‐part constraint is deliberate: `order >= vector` is the character guard (a scalar such as `isq::speed` has no magnitude, though the `magnitude` CPO would gladly run `std::abs` on its `double`), and `HasMagnitude<rep>` ensures the storage can deliver one. Returning `* unit` drops the precise `quantity_spec` to the unit's kind: a V2 convenience, since V2 cannot name the right result type (a scalar‐magnitude spec like `vec_mag<isq::force>[N]` is a V3 feature). This does not fix the character in general ‐ it collapses to `real_scalar` only for units built from scalar base units (e.g. `km/h`); for one tied to a vector spec (e.g. `N`) the result keeps `vector` character, so one could even take the magnitude of a magnitude. A known V2 limitation. == Return Value The norm of the numerical value, as a scalar quantity in the same unit. [NOTE] ==== The return value https://en.cppreference.com/cpp/language/attributes/nodiscard[should not be discarded^]. ==== [.small]#Created with https://www.mrdocs.com[MrDocs]#