View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
isodd: a pedestrian parity checker

4.5 | 2 ratings Rate this file 4 Downloads (last 30 days) File Size: 2.58 KB File ID: #24278 Version: 1.7
image thumbnail

isodd: a pedestrian parity checker


us (view profile)


27 May 2009 (Updated )

ISODD returns TRUE for integers of any numeric MATLAB class that are not evenly divisible by 2

| Watch this File

File Information

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

MATLAB release MATLAB 7.8 (R2009a)
Other requirements works with any MATLAB versions that knows about the BIT-function family
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
31 May 2011 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?

Comment only
31 May 2011 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)).

Comment only
31 May 2011 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.)

28 May 2009 Loginatorist

Loginatorist (view profile)

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

27 May 2009 1.1

an annoying typo was corrected

28 May 2009 1.2

changed the output TFODD to mark valid odd integers only; thus, the syntax vec(tfodd&tferr) now is simply vec(tfodd) for odd and vec(~tfodd&tferr) for even integers; version tag 28-May-2009 22:43:42

29 May 2009 1.3

help/example section reorganized; version tag 29-May-2009 15:03:56

29 May 2009 1.5

user request: ND arrays now return the results encapsulated in cells; version tag 29-May-2009 21:36:47

13 Aug 2009 1.6

any integer input now is typecast to double before testing; version tag 13-Aug-2009 23:18:39

14 Aug 2009 1.7

change in the help section; version tag 14-Aug-2009 20:35:23

Contact us