An error when converting from double to Ipp32f.

An error when converting from double to Ipp32f.

double value = 0;
Ipp32f pValD;
Ipp8u Buf[]="19970501";
value = atof((const char*)Buf);
pValD = (Ipp32f )value;

From debugger:
value19970501.000000000double
pValD19970500.float

the result in pValD=19970500 , not 19970501
this error occurs when converting from double to Ipp32f.

Do you have any explanation?

8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Quoting - thstart

double value = 0;
Ipp32f pValD;
Ipp8u Buf[]="19970501";
value = atof((const char*)Buf);
pValD = (Ipp32f )value;

From debugger:
value19970501.000000000double
pValD19970500.float

the result in pValD=19970500 , not 19970501
this error occurs when converting from double to Ipp32f.

Do you have any explanation?

Ipp32f is a 32bit floating point, double are generally 64 bits thus have more precision and can represent bigger numbers.

Not all natural numbers can be represented by floating points. In your case there is probably no representation for 19970501 in 32 bits but there is in 64 bits (I didn't do the math but you can convinced yourself if you look online for the internal representation of floating point).

Hope this help,

Emmanuel

Quoting - eweber

Ipp32f is a 32bit floating point, double are generally 64 bits thus have more precision and can represent bigger numbers.

Not all natural numbers can be represented by floating points. In your case there is probably no representation for 19970501 in 32 bits but there is in 64 bits (I didn't do the math but you can convinced yourself if you look online for the internal representation of floating point).

Hope this help,

Emmanuel

Yes you are right - flat has significant max 7 digits. The problem
is actually I need a fast conversion between string and Intel types.
In this case I have to use Microsoft's _atodbl. I am using vectors
and this would be a performance problem. Does Intel has a vector
string to Intel types conversion function?

Hello,
'Intel types' is nothing more than just typedefs (see ippdefs.h file)
typedef float Ipp32f;
typedef double Ipp64f;
We do not have string to typeconversion functions in IPP.
Regards,
Vladimir

Quoting - vdudnik

Hello,
'Intel types' is nothing more than just typedefs (see ippdefs.h file)
typedef float Ipp32f;
typedef double Ipp64f;
We do not have string to typeconversion functions in IPP.
Regards,
Vladimir

If they are just typedefs, how they are 32 bit aligned?

What do you mean? How typedef is related to memory alignment?

Quoting - vdudnik

What do you mean? How typedef is related to memory alignment?

I just want to use 32 bit memory alignment when for example create an array
and read from a disk file for example.

You mayuse ippMalloc/ippFree functions which provide you 32-bytes aligned memory buffer (so 32-bit alignment is guaranteed for sure)
Vladimir

Leave a Comment

Please sign in to add a comment. Not a member? Join today