# Odd and Even numbers

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 07/06/2010 at 16:50, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   11.5
Platform:   Windows  ;
Language(s) :     C++  ;

---------
Is it possible to determine if an index is odd or even?

~Shawn

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 07/06/2010 at 17:02, xxxxxxxx wrote:

Figured this out...  ended up using ...

if (Modulo(i, 2) != 0)

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 08/06/2010 at 05:44, xxxxxxxx wrote:

Don't do that if you're handling Integers and high volume, because Modulo is a Real function.

Easier using the C++ modulo operator:

if (i%2) {
}

Hope it helps!

Kabe

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 08/06/2010 at 05:57, xxxxxxxx wrote:

cheers,
Matthias

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 08/06/2010 at 09:06, xxxxxxxx wrote:

Anything wrong with the C++ operator?

Kabe

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 08/06/2010 at 10:04, xxxxxxxx wrote:

Originally posted by xxxxxxxx

Anything wrong with the C++ operator?

Kabe

Nothing wrong, in fact LModulo just wraps % with a special condition if a<0.

from c4d_tools.h

``````
inline Real Modulo(Real a, Real b)
{
if (b==0.0) return 0.0;
LONG n = (LONG) (a/b);

a -= n*b;
if (a<0.0) a+= b;

return a;
}

inline LONG LModulo(LONG a, LONG b)
{
if (!b) return 0;
if (a >= 0) return a%b;

a -= (a/b)*b;
if (a<0) a+= b;

return a;
}

inline LLONG LModulo(LLONG a, LLONG b)
{
if (!b) return 0;
if (a >= 0) return a%b;

a -= (a/b)*b;
if (a<0) a+= b;

return a;
}
``````

cheers,
Matthias