FMath::Square
#include "Math/UnrealMathUtility.h"
Access: public
Specifiers: staticconstexpr
Description
Returns A * A. Used to square a value without a temporary variable, and to clearly express squaring intent over the raw multiply expression.
Signature
template< class T >
static constexpr UE_FORCEINLINE_HINT T Square(const T A) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| A | T | The value to square. | — |
Return Type
T Caveats & Gotchas
- • Evaluates A exactly once — unlike writing A * A inline, there is no risk of double-evaluating a function call or expression with side effects.
- • For distance comparisons, prefer comparing squared distances (FMath::Square(Distance)) against a squared threshold rather than calling FVector::Size() — it avoids a square root.
Example
Squared-distance check to avoid Sqrt C++
// Cheaper than comparing Size() against a threshold
float DistSq = FVector::DistSquared(GetActorLocation(), TargetLocation);
if (DistSq < FMath::Square(ActivationRadius))
{
Activate();
} See Also
Tags
Version History
Introduced in: unknown
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?