Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Odd and Even Check 1

Status
Not open for further replies.

Recon1775

Aerospace
Jul 24, 2002
137
Does anyone know of a way to type an IF statement that checks if the input is odd or even?

Such as it outputs a 0 if it's even and a 1 if it's odd
Something like that?

THANKS!
 
Replies continue below

Recommended for you

I think I came up with a solution...

Not sure if there is an easier way, but...

test = if( (-1)^n, 1, even, odd)

If n is even it sends out a 1 if it's odd it sends out a -1.
 
That says that (2^54)-1 is even, in v5. I imagine that is a precision limit.



Cheers

Greg Locock

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor