Q:

Write a function isint that will receive a number input argument innum, and will return 1 for true if this number is an integer, or 0 for false if not. Use the fact that innum should be equal to int32(innum) if it is an integer

0

 Write a function isint that will receive a number input argument innum, and will return 1 for true if this number is an integer, or 0 for false if not. Use the fact that innum should be equal to int32(innum) if it is an integer. Unfortunately, due to round-off errors, it should be noted that it is possible to get logical 1 for true if the input argument is close to an integer. Therefore the output may not be what you might expect, as shown here.

>> isint(4)

ans =

 1

>> isint(4.9999)

ans =

 0

>> isint(4.9999999999999999999999999999)

ans =

 1

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

isint.m

function out = isint(innum)

% Returns 1 for true if the argument is an integer

% Format of call: isint(number)

% Returns logical 1 iff number is an integer

out = innum == int32(innum);

end

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now