Stremik Posted June 22, 2004 Share Posted June 22, 2004 This should be an easy one. It's actually kinda embarrassing because what I'm going to ask is probably something that people learn it 5th grade. Well. Guess I flanked out on that day. Anyway. I don't fully understand how do "exponent" and "modulus" work. Especially exponent. For instance: example from Expression Language PDF. 2 * 3^2 + 4 * 6 / 2 = 48 (that is: 36+12) I don't understand how 2*3^2 evaluates to 36. Anyone care to explain? Thank you! Vladimir Quote Link to comment Share on other sites More sharing options...
meshsmooth Posted June 22, 2004 Share Posted June 22, 2004 The order of execution should be "BOMDAS" Brackets, Operators, Multiplication, Division, Add, Subtract Better put would be First (brackets) , then second (operators), third(multiplication, division) , last (add, subtract) But this seems to be behaving as if First (brackets) , then second (operators, multiplication, division) , last (add, subtract) I can Quote Link to comment Share on other sites More sharing options...
Mario Marengo Posted June 22, 2004 Share Posted June 22, 2004 Hi Stremik, Yup. The expression language is a bit of a strange animal when it comes to operator precedence (and so is VEX for that matter), but you can find the order of precedence on the same page as that example It is given as: 1. ( ) Quote Link to comment Share on other sites More sharing options...
renderpipe Posted June 22, 2004 Share Posted June 22, 2004 Hello Stremik, Anyway. I don't fully understand how do "exponent" and "modulus" work.Especially exponent. For instance: example from Expression Language PDF. I too had to re-learn elementry math. I just bought one of those math books for dummies. Exponents is known as power, so 6^2 means "six to the second power" or 6 * 6 = 36. 6^3 means "six to the third power" or 6*6*6 = 216. You get the picture. When a number is raised to the second power (x^2), it is squared. Example: 6^2 can be written/said as "six squared." When a number is raised to the third power (x^3), it is cubed. Example: 6^3 can be written/said as "six cubed." I don't know if this is relevant to 3d but that's what my physics book says Law of Exponents tutorial: http://oakroadsystems.com/math/expolaws.htm Modulus is still confusing to me. I "think" it's the remainder of division operation. For example: 5 % 3 = 2. Because 5 /3 = 1 with 2 remainder, the modulus will just give you the remainder. Again this is what "I think." I hope somebody correct me if I am wrong. Good luck! Perry Quote Link to comment Share on other sites More sharing options...
mark Posted June 22, 2004 Share Posted June 22, 2004 yeah renderpipe is correct with modulus, e.g. 4 % 2 = 0 Quote Link to comment Share on other sites More sharing options...
anakin78z Posted June 22, 2004 Share Posted June 22, 2004 This comes from the link renderpipe sent out, and it's what I learned in school. Houdini however doesn't follow this rule, it seems. One warning: Remember the order of operations. Exponents are thefirst operation (in the absence of grouping symbols like parentheses), so the exponent applies only to what it's directly attached to. 3x Quote Link to comment Share on other sites More sharing options...
Mario Marengo Posted June 22, 2004 Share Posted June 22, 2004 Houdini however doesn't follow this rule, it seems. Yes, algebraically speaking, the behaviour of the expression language is *not* correct when applying the exponent. The reference is. The exponent should have the same precedence as the unary minus operator - i.e: immediately after grouping ops (like parentheses). But oh well... VEX doesn't suffer from this because it doesn't have an "exponent" operator, and precedence, in general, is the same as C++. But it does have a set of "gotchas" relating to automatic type promotion. I'd say that, as a rule of thumb, never use the "^" operator in the expression language. Instead, use the power function pow(). So the sample expression becomes 2 * pow(3,2) + 4 * 6 / 2 And it doesn't hurt to over-parenthesize either. For example; you may think that mult (*) has higher precedence than div (/) and think that the following results in 0.5 2 / 2*2 ... when in reality, the result is 2. So always write it as 2 / (2*2). It won't hurt performance to have too many parentheses. All languages have their little ideosyncrasies though. Quote Link to comment Share on other sites More sharing options...
anakin78z Posted June 22, 2004 Share Posted June 22, 2004 Yes, algebraically speaking, the behaviour of the expression language is *not* correct when applying the exponent. This really threw me off a while back. Kind of not what I expect from a package like houdini either. ... Actually, to get 36 the first part of the expression would have to be pow(2*3,2) It won't hurt performance to have too many parentheses. That's good to know Quote Link to comment Share on other sites More sharing options...
Stremik Posted June 22, 2004 Author Share Posted June 22, 2004 I see. Thank you all very much guys!!! It's all very clear now. And thanks for the link! I've been looking for something like that. Thanks again! Vladimir Quote Link to comment Share on other sites More sharing options...
edward Posted June 22, 2004 Share Posted June 22, 2004 3x Quote Link to comment Share on other sites More sharing options...
Mario Marengo Posted June 23, 2004 Share Posted June 23, 2004 So why would anyone expect 3x Quote Link to comment Share on other sites More sharing options...
Stremik Posted June 23, 2004 Author Share Posted June 23, 2004 Boy! The docs are really screwed up. Looks like here: It is given as: 1. ( ) Parentheses 2. - Negation 3. * / % ^ Mult, Div, Mod, Pow 4. + - Add, Sub 5. < > == != || && ! Logical ops And operators at the same level (as well as the expression as a whole) get evaluated from left to right (which is the final form of precedence). the order of precedence actually given in a fashion similar to Arabic languages. At least it's true for mod and pow Mario, thanks again! From now on I'll do as you suggest and check the stuff in texport first. Say. Is there an expression for Modulus like there is one for Exponent? I looked and didn't find anything. Quote Link to comment Share on other sites More sharing options...
hoknamahn Posted June 23, 2004 Share Posted June 23, 2004 If you mean a module as absolute value, this is abs(val) function. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.