function handle uint64 bug?
Show older comments
In R2014a I find,
uint64(2025027714713048816) %no problem, returns input
@(x) uint64(2025027714713048816) %complains about Unexpected MATLAB expression
@(x) uint64(20250277147130) %works
The implication would be that you cannot create a function handle that uses a uint64 constant that is larger than 2^53-1 .
Could someone check this in later versions?
2 Comments
Rakesh Chavan
on 17 Mar 2016
Edited: Walter Roberson
on 17 Apr 2016
Hi,
Is there any specific reason for creating a function handle with an input which is never used?
A better way to create a handle to a uint64 would be to use,
>> ah = @(x) uint64(x)
and then pass that value to ah as follows
>> ah(2025027714713048816)
This works as expected.
On a side note in MATLAB R2016a the following output is generated:
>> @(x) uint64(2025027714713048816)
ans =
@(x)uint64(2025000000000000000)uint64(27714713048816)
Whereas,
>> a = @(x) uint64(2025027714713048816)
gives the Error message:
Unexpected MATLAB expression.
As per the above outputs it makes sense as to why the assignment to an handle does not work out.
The reason for the first output being represented as two uint64's lies in the precision losses and mantissa size (52 bits for floating points). You can check the following documentation link for more information:
Hope this helps
regards
Rakesh
Walter Roberson
on 17 Apr 2016
Accepted Answer
More Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!