Log long double value

I am currently working with large numbers such as __int64 and long doubles and im fairly new to unreal myself. I have been spending hours trying to figure out how i can print long doubles as i need to check that all my calculations are correct but this is becoming an issue as from what i can tell UE_LOG does not support Long Doubles only floats.

In standard c++ this won’t be an issue as i can just use printf like

printf("%lg\n", pow(5.67 * 10,-8));

and that works fine but when i use %lg in UE_LOG like this

UE_LOG(YourInit, Warning, TEXT("test = %lg"), pow(5.67 * 10,-8));

It won’t compile.

Is there a way i can log long doubles within unreal or atleast see the output from printf?

1 Like

You could convert the long to a std::string, convert that to FString, and then send that to the log:

char Buffer[100];
snprintf(Buffer, sizeof(Buffer), "test = %lg", pow(5.67 * 10, -8));
std::string StdMessage = Buffer;
FString LogMessage(StdMessage.str());
UE_LOG(YourInit, Warning, TEXT("%s"), *LogMessage);

That gave me: “test = 9.36129e-15” in my log.

I don’t know if there’s a more direct route, but it works.

Just use %lf instead.

UE_LOGFMT(LogTemp, Log, "Printing three doubles: {0}, {1}, {2}", GetActorRotation().Pitch, GetActorRotation().Yaw, GetActorRotation().Roll);

Output Log:
LogTemp: Printing three doubles: 16.404666058434792, -8.4564431394870727, -46.881993375868063

more info can be found here:

1 Like