12/14/2020 12:19 PM  
Joined: 9/11/2014 Last visit: 4/28/2022 Posts: 18 Rating: (1) 
Hello, Using MOD function on Simotion, it does not return the expected value. For example: 20 MOD 360 = 20  Correct 380 MOD 360 = 20  Correct 20 MOD 360 = 20  Incorrect, expected value 340 Using another tools as windows calc, MOD function works with negative values retuning 340. Why this MOD functions does not work with negative values? Is there any other function for this situation or I need to create my own MOD function? Thanks 
12/14/2020 12:25 PM  
Joined: 1/4/2013 Last visit: 10/5/2022 Posts: 1061 Rating: (97) 
Probably because negative values are not commonly used in automation, so they "skipped" them. 20 degrees is not a physical quantity, since your "motor" ranges from 0 to 360. Mathematically you are right, of course. If you want you can make your own MOD function where you preprocess the input by adding the modulo if it is negative , and then applying the German MOD command 
Searching for Siemens used/new equipments ? 

12/14/2020 12:41 PM  
Joined: 9/11/2014 Last visit: 4/28/2022 Posts: 18 Rating: (1) 
Physicaly motor can't be in negative positions, but maybe you need to add some offset reaching to this situation where you need to MOD the value... Thanks for the answer, I will solve it with my own function. 
12/14/2020 3:23 PM  
Joined: 9/23/2005 Last visit: 10/5/2022 Posts: 3977 Rating: (623) 
And how would you like to prove, that this result is incorrect and that expected value is 340? 
Regards, 

12/14/2020 5:09 PM  
Joined: 1/4/2013 Last visit: 10/5/2022 Posts: 1061 Rating: (97) 
Well, Jacek, in fact you are completely right since (https://en.wikipedia.org/wiki/Modulo_operation).... "When exactly one of a or n is negative, the naive definition breaks down, and programming languagesdiffer in how these values are defined" And a and n are the two operans of Modulo... 
Searching for Siemens used/new equipments ? 

Follow us on