cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

Community Tip - You can change your system assigned username to something more personal in your community settings. X

7-Bedrock

## Relations statement to identify even or odd numbers.

I am trying to write a relation that goes something like this...

IF

Parameter = even number

dimension_x = .05

ELSE

dimension_x=0

ENDIF

I cannot figure out how to get Creo to tell if the Parameter (which is a integer type) is an odd or even number.

Any thoughts would be greatly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
21-Topaz I
(To:M.Shuler)

To do "int" you either have to use "floor" or "ceil".

The easier thing to do is use the "MOD(numerator, divisor)" function. To find out if a number is odd or even, it's something like

IF MOD ( number, 2 ) == 0

/* Do this stuff if even.

ELSE

/* Do this stuff if odd.

ENDIF

5 REPLIES 5
11-Garnet
(To:M.Shuler)

Without checking exactly what the syntax would be in Relations, the usual approach is:

if( x/2 = int(x/2) ) then it's even

Is there an int() in Relations?

21-Topaz I
(To:M.Shuler)

To do "int" you either have to use "floor" or "ceil".

The easier thing to do is use the "MOD(numerator, divisor)" function. To find out if a number is odd or even, it's something like

IF MOD ( number, 2 ) == 0

/* Do this stuff if even.

ELSE

/* Do this stuff if odd.

ENDIF

11-Garnet
(To:KenFarley)

Ah yes, that's a little neater.

I believe INT is usually equivalent to FLOOR (i.e. 'take the INTeger part', not 'round to nearest integer').

Yeah, to round things I usually "cheat" by doing something like floor ( number + 0.5 ). It's kind of weird the functions that are included and more importantly not included. I'd love to see a "real-to-string" function, so I wouldn't have to use multiple lines of code to do the same thing. It would also be kind of cool if there were some sort of ability to define our own functions. That would really make things simpler for me.

7-Bedrock
(To:KenFarley)

Worked exactly like I wanted it too. Thanks Kenneth.

Announcements