Functions that checks if a number is odd or even
Functions that checks if a number is odd or even.
(This is a little bit more complicated than using "mod(x, 2)" if you want error handling for certain cases.)
The function can handle double, single, and integer classes, as well as arrays of these.
* An error is raised if a floating point number is too large so that it is not possible to determine if it is even or odd.
* An error is raised if a floating point number contains a fraction or is a special number (Inf, -Inf, or NaN).
* The function can handle integers, also 64 bits. Care is taken so that the "weird number" in two complement form is handeled appropriately. Many other codes fail when taken the absolute value of the weird number integers. Note that int8(-128) = -128 in Matlab, but abs(int8(-128)) = 127!!!
By Ulf Carlberg 27-MAY-2011. Updated 29-MAY-2011.
BSD 2-clause license, see the file "license.txt".
Cite As
Ulf Carlberg (2023). Functions that checks if a number is odd or even (https://www.mathworks.com/matlabcentral/fileexchange/31593-functions-that-checks-if-a-number-is-odd-or-even), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.