1 members found this post helpful.
##
Even/Odd detection formula for use in families

Hi All,

I don't know if this has been done or not, or indeed if anyone else has ever wanted such a thing...

I have created a one-line formula that provides a boolean test (yes/no) of whether an input value is even or odd, for values greater than 1.

Create two parameters - one is the value you want to test. This **must** be an integer, so use either the integer class or use round(x) on another value. Let's use a parameter type integer, and call it **TEST**.

The second parameter is your boolean (yes/no) - call the parameter **EVEN**

Insert this formula in the formula field for the EVEN parameter:

Code:

(rounddown(TEST / 2)) - (rounddown((TEST - 1) / 2)) > 0

If the value of TEST is an even number, EVEN will be TRUE (ticked/yes); if TEST is an odd number, EVEN will be FALSE (unticked/no).

Where this might be useful:

I have used this in parametric door families for folder doors, to provide a boolean value to display the fixed leaf if an odd number of doors is used. I have also used it in shelving systems to allow a blank panel to appear when the shelves are odd. You might have some other uses for it.

Note that this will produce erratic results if provided with negative numbers, 0 or 1 as an input. This can be avoided through use of clever IF statements, and is left as an exercise for the reader.

How it works:

The formula tests the difference between a given value X/2 and (X-1)/2, with both values rounded down before the difference is performed. For an example value of 3 the equation is thus:

Code:

Input values: (3/2) - (3-1/2) = (3/2) - (2/2)
Result values: (1.5) - (1)
Rounded Down: (1) - (1) = 0 THEREFORE X is ODD where X=3

For an example value of 42:

Code:

Input values: (42/2) - (42-1/2) = (42/2) - (41/2)
Result values: (21) - (20.5)
Rounded Down: (21) - (20) = 1 THEREFORE X is EVEN where X=42

Adrian Esdaile : BIM Manager : BLP Sydney

Union Representative

Amalgamated Union of Philosphers, Sages, Luminaries and Other Professional Thinking Persons.

Sector ZZ9-Plural-Z-Alpha Chapter