Debug Game / Development間での計算の差分について

現在以下のようなFMathを使った処理を行った際にdebug gameとdevelopmentで僅かですが誤差が出ます。

以下の処理では変数 Yに小数第6位の誤差がありました。

小数第6位レベルの差分がビルドコンフィグレーションに影響されずに処理が行われることが期待しています。

現在、UEの方でビルドコンフィグレーションによって差分が大きくなるような要因のようなものがありますでしょうか?例えばFMathを使うよりcmathを使った方が良いなどありましたら、ご教授頂けると幸いです

<br/>

またより精度が高いのはdebug gameでしょうか?

合わせてdebug gameはfloatでの処理を行うにあたり、developmentと全く同じ精度や桁数を情報として持っているのかご教授頂けると幸いです

FString BuildConfig = UKismetSystemLibrary::GetBuildConfiguration();
 {
 FString OutputFilePath = FPaths::ProjectDir() + TEXT("Output_other.txt");
 if (BuildConfig == TEXT("DebugGame"))
 {
 OutputFilePath = FPaths::ProjectDir() + TEXT("Output_debug.txt");
 }
 else if (BuildConfig == TEXT("Development")) 
 {
 OutputFilePath = FPaths::ProjectDir() + TEXT("Output_develop.txt");
 }
 

FString OutputString;
 
float Theta = -1.244221f;
 int TotalNum = 37;
 float Coef = 141.500000f;
 
//ベクトルの計算
 float X = FMath::Cos(2 * PI * Coef / TotalNum) * FMath::Cos(Theta);
 float Y = FMath::Sin(2 * PI * Coef / TotalNum) * FMath::Cos(Theta);
 float Z = FMath::Sin(Theta);
 
OutputString = FString::Printf(TEXT("X : %.6f Y : %.6f Z : %.6f\n"), X, Y, Z);
 FFileHelper::SaveStringToFile(OutputString, *OutputFilePath);
 }



Hi 佳依 山本,

Thank you for reaching out. Internally, functions from the FMath structure will call the same implementation as their counterparts from the <cmath> standard header. What you are seeing is not Unreal-specific, but rather the effect of the Floating Point Model used by the compiler.

The “DebugGame” and “Development” configurations are comparable to applying Visual Studio’s “Debug” and “Release” configurations for your game code. While “DebugGame” uses the /fp:precise compiler option, “Development” uses /fp:fast by default, which relaxes strict adherence to floating-point standards to favor performance and memory optimizations. Importantly, /fp:fast allows the compiler to reorder, combine, or simplify floating-point operations, possibly resulting in observably different rounding behavior in some cases. You can find more information about this here.

If you need to ensure that “DebugGame” and “Development” configurations use the same Floating Point Model, the easiest way is to add the following lines to your code, on each source file that requires it:

#pragma float_control(precise, on)
#pragma fp_contract(off)

Starting in UE 5.4 (CL 26615577, commit 36ed1de), you can also control floating-point behavior on a per-target or per-module basis by adding “FPSemantics = FPSemanticsMode.Precise;” to your TargetRules or ModuleRules class. Note, though, that changing this on a module also requires setting it up with a “PrivatePCHHeaderFile” (docs). Changing on a target requires setting it up to use a unique “BuildEnvironment” (docs).

Before UE 5.4, changing the Floating Point Model on the build system level requires building UBT from source. Look for “/fp:fast” in file “VCToolChain.cs”.

I hope this is helpful. Please let me know if you need any further assistance.

Best regards,

Vitor