function handle uint64 bug?
显示 更早的评论
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 个评论
Rakesh Chavan
2016-3-17
编辑:Walter Roberson
2016-4-17
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
2016-4-17
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!