Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- Creo (Previous to May 2018)
- Creo Modeling Questions
- Relations statement to identify even or odd number...

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Oct 25, 2016
04:42 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Oct 25, 2016
04:42 PM

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.

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

Oct 26, 2016
06:59 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Oct 26, 2016
06:59 AM

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

Oct 26, 2016
04:16 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Oct 26, 2016
04:16 AM

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?

Oct 26, 2016
06:59 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Oct 26, 2016
06:59 AM

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

Oct 26, 2016
07:03 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Oct 26, 2016
07:03 AM

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').

Oct 26, 2016
08:31 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Oct 26, 2016
08:31 AM

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.

Oct 26, 2016
07:27 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Oct 26, 2016
07:27 AM

Worked exactly like I wanted it too. Thanks Kenneth.