Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

## An error when converting from double to Ipp32f.

Beginner
825 Views

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?

7 Replies
New Contributor I
825 Views
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

Beginner
825 Views
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?

Employee
825 Views
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,

Beginner
825 Views
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,

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

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

Beginner
825 Views
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.

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