Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uint64 is not exact for vectors in Matlab

Tags:

I have discovered an inconsistency for uint64 when using vectors in Matlab. It seems as an array of uint64 is not exact for all 64 bits. This did not give the output I expected,

p=uint64([0;0]);
p(1)=13286492335502040542
p =
 13286492335502041088
                    0

However

q = uint64(13286492335502040542)
q =
 13286492335502040542

does. It is also working with

p(1)=uint64(13286492335502040542)
p =
 13286492335502040542
                    0

Working with unsigned integers one expect a special behaviour and usually also perfect precision. This seems weird and even a bit uncanny. I do not see this problem with smaller numbers. Maybe anyone knows more? I do not expect this to be an unknown problem, so I guess there must be some explanation to it. I would be good to know why this happen and when, to be able to avoid it. As usual this kind of issues is mentioned nowhere in the documentation.

Matlab 2014a, windows 7.

EDIT

It is worth mentioning that I can see the same behaviour when defining arrays directly.

p=uint64([13286492335502040542;13286492335502040543])
p =
 13286492335502041088
 13286492335502041088

This is the root to why I ask this question. I have hard to see workaround for this case.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!