|
-
October 13th, 2009, 08:00 AM
#1
float casting problem
I recently encountered a weird problem that has to do with the VARIANT struct.
An external application has updated the VARIANT with a float value that conforms to the IEEE 754 standard (using Memory Watch, I verified that the bits are aligned correctly, representing a specific floating point value).
However when accessing the VARIANT using the fltVal member, the resulting float number is entirely different than expected.
The following code seems to have fixed the problem:
Code:
// 'v' is of VARIANT type
unsigned int uiVal = (unsigned int)v.fltVal;
float fVal = *((float*)&uiVal);
However, I'm not sure as to what has caused this problem and why the code above fixes it. I suspect this has something to do with the union type properties, but I'm not sure.
Any input is appreciated.
Regards,
Zachm
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|