07-24-2023, 12:35 PM
Consider the following code:
// Filename fputest.cpp
#include <cmath>
#include <cstdio>
int main()
{
double x;
*(__int64 *) &x = 0xc01448ec3aaa278di64; // -5.0712136427263319
double sine1 = sin(x);
printf("%016llX\n", sine1);
double sine2;
__asm {
fld x
fsin
fstp sine2
}
printf("%016llX\n", sine2);
return 0;
}
When compiled with Visual C++ 2012 (`cl fputest.cpp`) and the program is executed, the output is the following:
3FEDF640D8D36174
3FEDF640D8D36175
Questions:
- Why are these two values different?
- Is it possible to issue some compiler options so that the computed sine values will be exactly the same?
// Filename fputest.cpp
#include <cmath>
#include <cstdio>
int main()
{
double x;
*(__int64 *) &x = 0xc01448ec3aaa278di64; // -5.0712136427263319
double sine1 = sin(x);
printf("%016llX\n", sine1);
double sine2;
__asm {
fld x
fsin
fstp sine2
}
printf("%016llX\n", sine2);
return 0;
}
When compiled with Visual C++ 2012 (`cl fputest.cpp`) and the program is executed, the output is the following:
3FEDF640D8D36174
3FEDF640D8D36175
Questions:
- Why are these two values different?
- Is it possible to issue some compiler options so that the computed sine values will be exactly the same?