5.0

5.0 | 1 rating Rate this file 125 downloads (last 30 days) File Size: 2.58 KB File ID: #24278

isodd: a pedestrian parity checker

by us

 

27 May 2009 (Updated 14 Aug 2009)

Code covered by BSD License  

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

Download Now | Watch this File

File Information
Description

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

see
> 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
Zip File Content  
Other Files isodd.m,
license.txt
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
28 May 2009 Matt Fig

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

20 Aug 2009 PXlab

Maybe you are the Herbert West re-animator of Brian Yuzna masterpieces. I hope is so! :))

Please login to add a comment or rating.
Updates
27 May 2009

an annoying typo was corrected

28 May 2009

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

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

29 May 2009

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

13 Aug 2009

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

14 Aug 2009

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

Tag Activity for this File
Tag Applied By Date/Time
integer us 27 May 2009 15:51:16
parity us 27 May 2009 15:51:16
odd us 27 May 2009 15:51:16
even us 27 May 2009 15:51:16
bitmax us 27 May 2009 15:51:16
bitand us 27 May 2009 15:51:16
rem us 27 May 2009 15:51:16
mod us 27 May 2009 15:51:16
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com