We cast a data from char* array do double as in the following function:
double getDouble(const char* szData, const size_t dataLength)
{
double res = 0;
if(dataLength == 8)
{
ub8 doubleData = *(ub8*)(szData);
doubleData = ntohll(doubleData);
double* pDoubleData = (double*)(&doubleData);
res = *pDoubleData;
}
return res;
}
ub8 has size as 8 byte, unsigned long long. And the double value -1.1512299550195975 is converted as 3.6975400899608046. But input and output should be equal(equal to -1.1512299550195975). This case is only happened in AIX. In the another platforms we get correct result.
We use optimization level O2 for our project. If I used optimization level as O1 , then data is converted correctly. Can you help me, please, what do you think, why conversion is correct for optimization level O1 and why it is incorrect for optimization level O2? May be I should to turn off or on some flags for aix in the compilation? Thank you. Aix compiler version is 13.1.3.
We get double value in the char array format from binary file. We parsing data from transaction logs of oracle database. And oracle writes , for example, double value as '40 0d 94 8f e6 10 3e 93' and we should convert is as '-1,1512299550195975' in the double type value. But in the only aix we get '3,6975400899608046' incorrect value