Output of mod() for large input
1 次查看(过去 30 天)
显示 更早的评论
In the Stanford online course in probabilistic graphical models, they use their own linear congruential random number generator. The results from that generator differ between R2012a and earlier versions of MATLAB, and I boiled it down to a difference in the calculation of mod() for a very large number:
mod(25754210418041856,179424673)
Since the first argument is 17 digits, and therefore not accurately stored as an integer, it is no surprise to me that mod() might struggle; but I am wondering if anyone can give me some more specific insight as to why the behavior may have changed from version R2011b to R2012a.
采纳的回答
Richard Brown
2012-4-23
@Walter Roberson is correct, in R2012a MATLAB automatically casts the number into a uint64. For this piece of code
[mod(25754210418041856,179424673), mod(uint64(25754210418041856),179424673)]
In R2011b I get this:
149629568 149629566
In R2012a I get this:
149629566 149629566
1 个评论
Richard Brown
2012-4-23
Also, from the release notes for R2012a:
"The following functions show improved performance:
Arithmetic and similar basic math functions for double, single, and integer data types."
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!