PDA

View Full Version : is qreal equivalent to float32?



pdoria
22nd July 2009, 15:35
Hi,

Knowing this is a lame question that should be posted in the Newbie section... :o
But what's the exact equivalent for float32 in QT4 ?

Thank you!

Pedro Doria Meunier

wysota
22nd July 2009, 15:47
There is none. There is qreal available but it maps to double on all architectures apart ARM where it maps for float for efficiency reasons. So qreal really depends on the size of double on your architecture.

pdoria
22nd July 2009, 15:54
Thanks wysota

The thing is I have the following decl:


typedef struct
{
float32 altitude;
float32 epe;
float32 eph;
float32 epv;
uint16 type_of_gps_fix;
float64 time_of_week;
double_position_type position;
float32 east_velocity;
float32 north_velocity;
float32 up_velocity;
float32 mean_sea_level_height;
sint16 leap_seconds;
uint32 week_number_days;
} pvt_data_type;


How am I supposed to convert this to QT4 ? :o

BR,
Pedro Doria Meunier

wysota
22nd July 2009, 16:02
Why do you have to "convert" it? What's wrong with how it looks now?

By the way, you can always use double instead of float32. There is no problem in using a broader range type, there is no information loss.

pdoria
22nd July 2009, 16:07
Please correct me if I'm wrong...

Isn't float and double of sizes 32 and 64, respectively, regardless of architecture, being a IEEE standard?

This what I've come up with:


typedef struct
{
float altitude;
float epe;
float eph;
float epv;
quint16 type_of_gps_fix;
double time_of_week;
double_position_type position;
float east_velocity;
float north_velocity;
float up_velocity;
float mean_sea_level_height;
qint16 leap_seconds;
quint32 week_number_days;
} pvt_data_type;


BR,
Pedro Doria Meunier

wysota
22nd July 2009, 16:28
Isn't float and double of sizes 32 and 64, respectively, regardless of architecture, being a IEEE standard?

No. It depends on the architecture.

pdoria
22nd July 2009, 17:02
Hi again,

Fortunately I have both 32 and 64 bit archs to test this... ;)

the following piece of code yields the same result on both archs:

#include <iostream>
#include <cstdlib>

using namespace std;

int main(int argc, char *argv[])
{
cout << "Size of float: " << sizeof (float) << endl;

return EXIT_SUCCESS;
}

// Size of float == 4

I'm wondering which other archs don't produce the same result...

BR,
Pedro Doria Meunier

wysota
22nd July 2009, 20:27
8b, 16b, other 32b and 64b that you didn't check. Remember world doesn't end on Intel architecture.

pdoria
22nd July 2009, 23:13
wysota,

you're absolutely right.
But that's what I've got to work with ... :)

BR,
Pedro

wysota
22nd July 2009, 23:57
So the question was pointless in the first place. You could have just checked the field size on all possible deployment environments.