File Exchange

image thumbnail

isodd: a pedestrian parity checker

version (2.58 KB) by us
ISODD returns TRUE for integers of any numeric MATLAB class that are not evenly divisible by 2

1 Download

Updated 14 Aug 2009

View Version History

View License

ISODD returns TRUE for members (N) of a numeric array, which
- are within the range of ±bitmax
- are integers such that N == fix(N)
- are integers not evenly divisible by 2

Unlike the typical computational approach using REM/MOD,
ISODD produces a not-valid flag for numbers, which are
1) not an integer
2) larger than the maximum possible double precision
integer representation (±bitmax)
and does never return their parity as being odd

REM/MOD, on the other hand, do not complain if an input
is not a valid candidate for being even or odd at all
and, therefore, are NOT reliable parity checkers

> help isodd
for usage and a brief example for this small utility

Cite As

us (2021). isodd: a pedestrian parity checker (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

Ulf Carlberg

Another thing that confuses me:
>> [a,b]=isodd(1:5)
a =
1 0 1 0 1
b =
1 0 1 0 1
Shouldn't "b" be all ones in this case?

Ulf Carlberg

I found a bug:
>> x=int8(-128)
x =
>> isodd(x)
ans =
because abs() will round the result to fit in int8, so abs(x)=127. Same for all "weird numbers" in two complement form intN(-2^(N-1)).

Ulf Carlberg

I uploaded a similar function, but with only one input and one output. An error is raised if input is wrong. It depends on the application what is most useful i guess. (My function also had a few bugs first, but I hope it is sorted out now. The updated version should appear soon.)

Matt Fig

Finally, a standard file which can be referenced for the perennial NG question! Well done. Thanks Urs.

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!