LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert extended precision float to float in C++

Solved!
Go to solution

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

0 Kudos
Message 1 of 5
(4,999 Views)
Solution
Accepted by topic author Victor King
You can search for data types, numeric in LabVIEW help for details on the different datatypes. Before sending the data to the C++ application, you can use the To Double Precision function on the Numeric / Conversion palette to convert it to a Double Precision number.
Message 2 of 5
(4,990 Views)

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
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 3 of 5
(4,977 Views)

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

0 Kudos
Message 4 of 5
(4,948 Views)

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

Message Edited by rolfk on 01-22-2009 07:18 AM
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 5 of 5
(4,932 Views)