Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X
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.
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
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?
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
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.
Worked exactly like I wanted it too. Thanks Kenneth.