Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

General question. Seeing error in lower digits when doing simple dgemm example

RJ5
Beginner
420 Views

Hi,

 

I am new to MKL. I started by doing a basic example which creates an NxM matrix A.  A consists of random numbers between -1 and 1 and can contain one digit after the decimal point only. For example, -0.1 might be there but not -0.12

I then used dgemm to calculate A*Atranspose.

I compared the answer to my manual calculation

For some elements, there appears to be some error.

 

For example if my manual calculation calculates 123.45 then dgemm is returning 123.45000000006789 . The lower digits are obviously junk as it is simply a sum of products of numbers to one decimal place each.

 

Is this expected behaviour?

 

 

 

 

0 Kudos
4 Replies
Gennady_F_Intel
Moderator
420 Views

yes, this is an expected rounding error results 

0 Kudos
RJ5
Beginner
420 Views

Thank you very much for the response. Is there any advised way to handle this?

 

I was surprised to see it as I thought it would just be a simple "sumproduct" type of calculation for numbers exact to one significant digit, and therefore that each product would be exact, but I guess that there is some optimisation going on underneath.

0 Kudos
Hinds__David
Beginner
420 Views

Your inputs cannot be represented exactly as binary floating point numbers. Try googling for "ieee 754 calculator".

 

0 Kudos
mecej4
Honored Contributor III
420 Views

RJ: Your manual calculations will not match the computed results unless both were performed using the same number system. In particular, if your manual calculations were performed using base 10, you should expect differences.

Consider the number 0.110. Its mantissa can be expressed exactly in decimal with a single significant digit. In IEEE-64 bit binary, even 53 bits are not sufficient to represent the same number exactly.

0 Kudos
Reply