Share via


編譯器警告 (層級 3) C4738

在記憶體中儲存 32 位元浮點結果,可能會損失效能

C4738 警告指派、轉換、傳遞引數或其他作業的結果可能需要四捨五入,或者作業用完暫存器,而且需要使用記憶體(溢出)。 這可能會導致效能遺失。

若要解決此警告並避免四捨五入,請使用 /fp:fast 編譯或使用 double ,而不是 float

若要解決此警告並避免用完暫存器,請變更計算順序並修改內嵌的使用

此警告預設為關閉。 如需詳細資訊,請參閱 Compiler Warnings That Are Off by Default

範例

下列範例會產生 C4738:

// C4738.cpp
// compile with: /c /fp:precise /O2 /W3
// processor: x86
#include <stdio.h>

#pragma warning(default : 4738)

float func(float f)
{
    return f;
}

int main()
{
    extern float f, f1, f2;
    double d = 0.0;

    f1 = func(d);
    f2 = (float) d;
    f = f1 + f2;   // C4738
    printf_s("%f\n", f);
}