RealDocs

UKismetMathLibrary::SignOfInteger

function Engine Blueprint Since 4.0
#include "Kismet/KismetMathLibrary.h"
Access: public Specifiers: staticBlueprintPure

Description

Returns -1 if A is negative, 0 if A is zero, or +1 if A is positive. Useful for normalising a direction or difference into a unit step.

Caveats & Gotchas

  • Returns 0 for an input of 0, not 1. If your algorithm requires a non-zero sign (e.g. for direction selection), handle the zero case explicitly.
  • For floats use SignOfFloat (or FMath::Sign); mixing SignOfInteger with a float cast can lose precision for values outside the exact int32 range.

Signature

static UE_INL_API int32 SignOfInteger(int32 A);

Parameters

Name Type Description Default
A int32 The integer whose sign is to be determined.

Return Type

int32

Example

Determine scroll direction C++
int32 ScrollDelta = NewPage - CurrentPage;
int32 Direction = UKismetMathLibrary::SignOfInteger(ScrollDelta);
// Direction is -1, 0, or +1

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.