How do I test for integers in MATLAB?

前端 未结 7 1350
遥遥无期
遥遥无期 2021-01-04 00:55

I\'m writing a program that will calculate factorials of integers. However, the part I\'m stuck on is if someone enters a non-integer such as 1.3, I\'d like to

相关标签:
7条回答
  • 2021-01-04 01:44

    By double command, you cannot get the correct answer:

    >> double(uint64(21/22))
    ans =
         1
    >> double(uint64(22/22))
    ans =
         1
    

    also floor,round,... have problem with such cases:

    floor(22/22)==21.99999999999999999999999999999999999/22
    

    but mod seems can distinguish 22/22 and 21.99999999999999999999999999999999999/22:

    >> mod(22,22)
    ans =
         0
    >> (21.99999999999999999999999999999999999/22)
    ans =
         1
    
    0 讨论(0)
提交回复
热议问题