01-20-2009 11:40 PM
Hi,
Could anyone please me how to convert extended precision float (floatExt) to normal float in C++?
What's the difference in float data type between Labview and C++?
When I tried to receive a float array from a DLL function generated by Labview in C++, the data is wrong.
Thanks,
Victor King
Solved! Go to Solution.
01-21-2009 12:49 AM
01-21-2009 02:21 AM
Victor King wrote:Hi,
Could anyone please me how to convert extended precision float (floatExt) to normal float in C++?
What's the difference in float data type between Labview and C++?
When I tried to receive a float array from a DLL function generated by Labview in C++, the data is wrong.
Thanks,
Victor King
Ravens suggestion is the most easy thing. LabVIEWs extended floating point number on Windows x86 is a 10 byte number in the format as used by the FPU. Theoretically you can represent it in C/C++ like this:
typedef struct {
int32 mlo, mhi;
int16 e;
} floatExt;
But the whole business of converting between double and extended format is rather nasty bit shuffling and it is much easier to simply convert to double on the LabVIEW side.
Besides why are you using extended at all? It doesn't really bring a lot of advantages at all not even in LabVIEW as most LabVIEW libraries work with doubles anyhow!
Rolf Kalbermatter
01-21-2009 03:50 PM
Thanks for your advice.
I already converted floatExt to single precision and it works.
I just wish to know the secret in the floatExt data type as the returned values in floatExt seem to be very strange to me.
One more question, what is the difference in float data type between C++ and Labview?
When I tried to receive a float array from Labview generated DLL, the contents are different from what I got in Labview.
Thanks,
Best regards,
Victor King
01-22-2009 12:14 AM - edited 01-22-2009 12:18 AM
Victor King wrote:Thanks for your advice.
I already converted floatExt to single precision and it works.
I just wish to know the secret in the floatExt data type as the returned values in floatExt seem to be very strange to me.
One more question, what is the difference in float data type between C++ and Labview?
When I tried to receive a float array from Labview generated DLL, the contents are different from what I got in Labview.
Thanks,
Best regards,
Victor King
There is no secret. normal floats and doubles are both the same in LabVIEW and C. They are simply IEEE floating point numbers. floatExt is on x86 platforms the numeric format as defined by the Intel x86 FPU. Any "secret" about this type is documented in the according Intel databooks.
The only reason the value of floats and doubles could appear different in LabVIEW and C is if you happen to pass them through the Typecast somehow. But there is only a need for typecasting if you happen to transfer them over some bytestream protocol such as TCP/IP. With a Typecast the Endianess of numbers including floats gets affected in LabVIEW, since LabVIEW always assumes Big Endian format on the bytestream side and does according byte and word swapping.
Rolf Kalbermatter