12/14/2020 12:19 PM  
Joined: 9/11/2014 Last visit: 12/15/2021 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: 1/26/2022 Posts: 1000 Rating: (88) 
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 
ChristophD supporter ! 

12/14/2020 12:41 PM  
Joined: 9/11/2014 Last visit: 12/15/2021 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: 1/28/2022 Posts: 3710 Rating: (582) 
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: 1/26/2022 Posts: 1000 Rating: (88) 
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... 
ChristophD supporter ! 

Follow us on