about palindrome number check
9 次查看(过去 30 天)
显示 更早的评论
%i have number n and i want to check whether that is palindrome
%but the n is too big so i cant use this code,what should i do
%example n= 1.76536927729736e+16
%my code is
if n==str2num(flip(num2str(n)))
flag=true
else
flag=false
end
5 个评论
Stephen23
2021-5-14
As Jan wrote you could store the digits as CHAR or UINT8, which also makes your palindrome checking easy.
采纳的回答
Jan
2021-5-14
For numbers up to 2^53 the type double represents the digits exactly. This is 9-0e15. See flintmax.
Your example n=1.76536927729736e+16 exceed this limit. Therefore doubles are not useful fpr your needs. You cannot even store the value exactly in a double. Maybe you need an UINT8 vector containing the digits, or a CHAR vector.
It does not matter, if the value is displayed in the e notation or not, because this can be controlled by the command: format
9 个评论
Jan
2021-5-15
编辑:Jan
2021-5-15
@Walter Roberson: You are right. Thanks for finding this wrong assumption.
When I type this in the command window:
for k = 1:inf, end
No error occurs. Stopping this with Ctrl-C show a warning:
Warning: FOR loop index is too large. Truncating to 2147483647. % R2009b/32
Warning: FOR loop index is too large. Truncating to 9223372036854775807. % R2009b/64, 2018b
I've deleted my wrong claim. Maybe this failed in Matlab 6.5 and I did not try it again.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!