FMath::Sqrt
#include "GenericPlatform/GenericPlatformMath.h"
Access: public
Specifiers: static
Description
Returns the square root of Value. A double overload exists. For performance-critical code where precision is less important, consider FMath::InvSqrt.
Signature
static UE_FORCEINLINE_HINT float Sqrt(float Value) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Value | float | The value to compute the square root of. Must be non-negative. | — |
Return Type
float Caveats & Gotchas
- • Passing a negative value produces NaN on all platforms. Guard with FMath::Abs or a >= 0 check if the input sign is uncertain.
- • Square root is expensive relative to a squared comparison. When checking distances, compare squared values (FVector::DistSquared vs FMath::Square(Threshold)) to avoid calling Sqrt entirely.
- • FMath::InvSqrtEst provides a fast approximate reciprocal square root — useful for normalising vectors in non-critical paths, but not precise enough for physics or rendering.
Example
Compute vector magnitude manually and time-based ramp C++
// Manual magnitude (prefer FVector::Size() in practice)
float Magnitude = FMath::Sqrt(V.X*V.X + V.Y*V.Y + V.Z*V.Z);
// Ease-in curve using square root
float Alpha = FMath::Clamp(ElapsedTime / Duration, 0.0f, 1.0f);
float EasedAlpha = FMath::Sqrt(Alpha); // fast start, slow end See Also
Tags
Version History
Introduced in: unknown
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?