I’m using FMod to check whether a float is even or odd, but it says 2.000 % 2 = 2.
Here’s the function:
FIntPoint AGrid::GetHexagonIndex(FVector gridlocation)
{
FVector2d SnappedGridLocation(UUtilitiesLibrary::SnapVectorToVector(gridlocation * FVector{1,2,1}, _TileSize * FVector{ 0.75, 0.25 , 1 }));
FVector2d TempIndex(SnappedGridLocation / (FVector2d(_TileSize) * FVector2D{0.75, 1}));
UE_LOG(LogTemp, Display, TEXT("TempIndex %f : %f"), TempIndex.X, TempIndex.Y);
UE_LOG(LogTemp, Display, TEXT("FMath::Fmod(TempIndex.X, 2) = %f"), FMath::Fmod(TempIndex.X, 2));
if (FMath::Fmod(TempIndex.X, 2) == 0)
{
FIntPoint Index = FIntPoint(FMath::TruncToInt(TempIndex.X), FMath::TruncToInt(FMath::RoundToFloat(TempIndex.Y / 2) * 2));
return Index;
}
else
{
FIntPoint Index = FIntPoint(FMath::TruncToInt(TempIndex.X), FMath::TruncToInt(FMath::Floor(TempIndex.Y / 2) * 2 ) +1);
return Index;
}
return FIntPoint(-999, -999);
}
And here’s the log:
I tried checking the documentation, but found nothing. Can anyone explain why is this happening?